Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old February 20th, 2004, 02:25 PM
rho rho is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Toronto, Canada
Posts: 45 rho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
checkbox & onClick

This is my task: when a user selects/deselects a checkbox, I want the page to refresh and update the MYSQL database.

The variable I am passing is the checkbox 'trackEnabled'.

Here is my code. Please help!


php Code:
Original - php Code
  1.  
  2. // Get Passed Info
  3. $sessionID = $_GET['sessionID'];
  4.  
  5. if (!empty($_POST['trackEnabled'])) {
  6. $trackEnabled = $_POST['trackEnabled'];
  7.  
  8.     if ($trackEnabled == "on") {
  9.       $trackStatus  = '1';
  10.     } else {
  11.       $trackStatus = '0';
  12.     }
  13.  
  14.     $thisQuery = "UPDATE " . $table2 . " SET ".
  15.                  "trackEnabled='".($trackStatus)."', ".
  16.                  "WHERE trackID='".$_POST['trackEnableId']."'";
  17. echo $thisQuery;
  18.  
  19. //    $myResult = mysql_query($thisQuery, $myDB);
  20. }
  21.  
  22.  
  23. while ($myRow = mysql_fetch_array($myResult, MYSQL_ASSOC)) {
  24.   echo("
  25.   <TR>
  26.     <TD>".stripslashes($myRow['trackDisplayName'])."</A></TD>
  27.     <TD>".stripslashes($myRow['trackLocation'])."</TD>
  28.     <TD><A HREF='".$tracks_edit."?type=edit&&sessionID=".$myRow['sessionID']."&&trackID=".$myRow['trackID']."'>Edit Track</A></TD>
  29.     <TD>");
  30.     $disabled = 0;
  31.     $enabled = 1;
  32.     echo ("<FORM METHOD="POST" ACTION="tracks_display.php?sessionID=".$_GET['sessionID']."">n");
  33.     echo ("    <INPUT TYPE="checkbox" NAME="trackEnabled"" . (($myRow['trackEnabled'] == $enabled) ? " CHECKED" : "") ." onClick="window.location.href='tracks_display.php?sessionID  =".$_GET['se$
  34.     echo ("  </TD></TR>n");
  35.  
  36. }
  37.   echo("  <TR>
  38.     <TD><A HREF='".$tracks_edit."?sessionID=".$_GET['sessionID']."'>Add Track</A></TD>
  39.   </TR>");
  40.  


Reply With Quote
  #2  
Old February 20th, 2004, 02:46 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: checkbox & onClick

you forgot to state your problem

Reply With Quote
  #3  
Old February 20th, 2004, 03:20 PM
rho rho is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Toronto, Canada
Posts: 45 rho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: checkbox & onClick

It's not working!

Ok, well I get it to refresh all right... however, it doesn't seem to update the database.

Reply With Quote
  #4  
Old February 20th, 2004, 03:48 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: checkbox & onClick

is it passing trackEnabled okay? because without actually submitting the form i'm not sure it'll take the POST method.. maybe your value is within $_GET or $_REQUEST

Reply With Quote
  #5  
Old February 20th, 2004, 03:56 PM
rho rho is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Toronto, Canada
Posts: 45 rho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: checkbox & onClick

I just did print_r{$_POST) and it isn't returning anything.

arghh

Reply With Quote
  #6  
Old February 20th, 2004, 04:52 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: checkbox & onClick

and so what about print_r($_REQUEST) ?

Reply With Quote
  #7  
Old February 20th, 2004, 04:58 PM
rho rho is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Toronto, Canada
Posts: 45 rho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: checkbox & onClick

When I do print_r($_REQUEST)
I get:

Array ( [sessionID] => 1 )

Reply With Quote
  #8  
Old February 20th, 2004, 05:56 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: checkbox & onClick

k it's not passing your trackEnabled, you'll need to add it to your onclick event, something like so:
php Code:
Original - php Code
  1.  
  2. window.location.href='tracks_display.php?sessionID  =".$_GET['sessionID']."&trackEnabled=checked"'

then call it through $_REQUEST instead of $_POST

Reply With Quote
  #9  
Old February 20th, 2004, 06:16 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: checkbox & onClick

Sorry to butt in, but one other thing you could do is change the onChange event to submit the form instead of doing a location redirect. it would look something like

onChange="document.form.submit()"

It would probably be beneficial to give the form a name and then use that name in the onChange event. That way you shouldn't have to change anything else in the script.

Reply With Quote
  #10  
Old February 20th, 2004, 06:56 PM
rho rho is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Toronto, Canada
Posts: 45 rho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: checkbox & onClick

Here is my code with changes. I can't seem to get it to update still... When I do print_r, I get an array but with the wrong trackEnabledID... it only reads the LAST entry...

php Code:
Original - php Code
  1.  
  2.  
  3. // Opens Connection to Database
  4. include('connect.php');
  5.  
  6. // Get Passed Info
  7. $sessionID = $_GET['sessionID'];
  8.  
  9.  
  10. if (!empty($_POST['trackEnabled'])) {
  11. $trackEnabled = $_POST['trackEnabled'];
  12. $trackEnabledID = $_POST['trackEnabledID'];
  13.  
  14. print_r($_POST);
  15.  
  16.     if ($trackEnabled == "on") {
  17.       $trackStatus  = '1';
  18.     } else {
  19.       $trackStatus = '0';
  20.     }
  21.     $thisQuery = "UPDATE " . $table2 . " SET ".
  22.                  "trackEnabled='".$trackStatus."', ".
  23.                  "WHERE trackID='".$_POST['trackEnabledID']."'";
  24.  
  25. echo $thisQuery;
  26. $thisResult = mysql_query($thisQuery, $myDB);
  27. }
  28.     $disabled = 0;
  29.     $enabled = 1;
  30.     echo ("<FORM METHOD="POST" NAME="trackStatus" ACTION="tracks_display.php?sessionID=".$_GET['sessionID']."">n");
  31.     echo ("    <INPUT TYPE="hidden" NAME="trackEnabledID" value="".$myRow['trackID']."">n");
  32.     echo ("    <INPUT TYPE="checkbox" NAME="trackEnabled"" . (($myRow['trackEnabled'] == $enabled) ? " CHECKED" : "") ." onChange="document.trackStatus.submit()">");
  33.  
  34.  
  35.     echo ("  </TD></TR>n");
  36.  
  37. }
  38.   echo("  <TR>
  39.     <TD><A HREF='".$tracks_edit."?sessionID=".$_GET['sessionID']."'>Add Track</A></TD>
  40.   </TR>");



Reply With Quote
  #11  
Old February 20th, 2004, 06:58 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: checkbox & onClick

Quote:
Sorry to butt in
HOWW, DAAREE Y.... no wait, that was a good suggestion

Reply With Quote