Jump to content

Nightkon

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Everything posted by Nightkon

  1. I know that this is streching on a bit but any additional help or direction would be greatly appreciated.
  2. Not sure exactly Whizard it was part of the original code that I was working with. I have been leaving that whole section of code out and it doesn't make any difference.
  3. Thanks Darklink. I am now able to tell if the checkbox is checked or not based on the changes you suggested. The only issue now is getting the '1' or the '0' to save back to the database correctly. I have tried altering the update PHPCHECK.php file which is supposed to update the database but have had no luck. Any help would be appreciated. Thanks
  4. Thanks Marklarah. I am now using the correct function but the checkbox still does not save properly ??? Thanks for your help though I must be getting close
  5. Does anyone have any ideas? Thanks
  6. I also noticed that if you change the code "if ($val1=="0") {" in the CAR_checkbox file to "if ($val1=="1") {" the checkbox is always checked when the save button is clicked.
  7. Still have the same problem. Thanks though Hellbringer
  8. Hi All, I have a basic Checkbox in PHP which saves to a MYSQL database. I am able to create a Checkbox which correctly populates from the MYSQL table. The issue is that when a user clicks on the save button the information is not saved back to the database correctly. Basically if you check the boxes and save the database record is set to 0 (unchecked) and the checkboxes return to an unchecked state. I suspect that the code is unable to determine if the checkbox is checked when it saves as there are no errors being returned during the update process. The Table is called car_checkbox and has the fields FileSerial (Primary Key), year_2006 and year_2007. The .php files I am using are TESTPHPCHECK.php which contains the code used for updating the Checkbox. TESTCheckbox.php which holds the form and table. CAR_Checkbox which is the code for the checkbox itself and populates the values stored in the table. If anyone has any solutions or advice it would be very much appreciated. Thanks in advance. CAR_checkbox.php <?php include("mysql_connect.php"); $q="SELECT * FROM `car_checkbox` WHERE `FileSerial` = '$id'"; $r=mysql_query($q); $num=mysql_numrows($r); if ($num>0) { $val1=mysql_result($r,'0','year_2006'); $val2=mysql_result($r,'0','year_2007'); } else { //Else nothing is checked $val1=0; $val2=0; } //Show form echo "<input type='hidden' name='id' value='$id'>"; if ($val1=="0") { echo "<input name='year_2006' type='checkbox' value='year_2006'>2006"; } else { echo "<input checked='checked' input name='year_2006' type='checkbox' value='year_2006'>2006"; } if ($val2=="0") { echo "<input name='year_2007' type='checkbox' value='year_2007'>2007"; } else { echo "<input checked='checked' input name='year_2007' type='checkbox' value='year_2007'>2007"; } ?> TESTCheckbox.php I believe the code at the start of TESTCheckbox.php may have something to do with the issue but I have not been able to work it out. <?php include ('./populate.php'); ?> <?php $id=$_GET['id']; $val1=$_GET['year_2006']; if ($val1=="on") { $val1=1; } else { $val1=0; } $val2=$_GET['year_2007']; if ($val2=="on") { $val2=1; } else { $val2=0; } ?> <table width='1044' align="left" cellpadding="0" cellspacing="0" > <form action="TESTPHPCHECK.php?id=$id" method="POST" name='theForm' onsubmit=''> <input type="hidden" name="id" value="<?php echo $id; ?>"> <!--DWLayoutTable--> <td height="117" colspan="17" valign="top"><INPUT name="image" TYPE="image" class='forminput' value="Save" SRC="Buttons/NavBanner.gif" /> <h3><?php echo $row->current_name; ?></h3></td> <td width="11"> </td> <tr> <td height="13"></td> <td></td> <td colspan="5" rowspan="2" valign="top" class="edit">CAR Recd. </td> <td rowspan="2" align="center" valign="top"><?php include ('CAR_checkbox.php'); ?></td> <td></td> <td></td> <td></td> <td></td> </tr> </form> </table> TESTPHPCHECK.php <?php include("mysql_connect.php"); $val1 = $_POST['year_2006']; $val2 = $_POST['year_2007']; $id = $_POST['id']; $query17 = mysql_query("UPDATE car_checkbox SET year_2006='$val1' WHERE FileSerial='$id'") or die(mysql_error()); $query18 = mysql_query("UPDATE car_checkbox SET year_2007='$val2' WHERE FileSerial='$id'") or die(mysql_error()); ## The above statements run the whole query ## tyr adding some error checking if(!$query17){ echo "There is an error with query 17 <br>"; } else { echo "Query 17 was successful<br>"; } if(!$query18){ echo "There is an error with query 18 <br>"; } else { echo "Query 18 was successful<br>"; } #for more error checking you can try checking your posted variables with print_r($_POST); mysql_close($link); ?>
  9. I'm still having no luck with getting the Checkbox to update properly but I feel that it is pretty close. I have reposted my code as I have made a few changes. I have realised that when working with the code that creates the Checkbox whatever the value is in this section of code ' if ($val1=="0") ' (in CAR_checkbox //show form) is what the checkbox will be saved as (in this case the value 0 will be saved to the table even if the checkbox was checked). So I don't think that the code is able to determine if the checkbox is checked. I hope this makes sense and thanks for all the help thus far. CAR_checkbox <?php include("mysql_connect.php"); $q="SELECT * FROM `car_checkbox` WHERE `FileSerial` = '$id'"; $r=mysql_query($q); $num=mysql_numrows($r); if ($num>0) { $val1=mysql_result($r,'0','year_2006'); $val2=mysql_result($r,'0','year_2007'); } else { //Else nothing is checked $val1=0; $val2=0; } //Show form echo "<input type='hidden' name='id' value='$id'>"; if ($val1=="0") { echo "<input name='year_2006' type='checkbox' value='year_2006'>2006"; } else { echo "<input checked='checked' input name='year_2006' type='checkbox' value='year_2006'>2006"; } if ($val2=="0") { echo "<input name='year_2007' type='checkbox' value='year_2007'>2007"; } else { echo "<input checked='checked' input name='year_2007' type='checkbox' value='year_2007'>2007"; } ?> TESTCheckbox.php I believe the code at the start of TESTCheckbox.php may have something to do with the issue but I have not been able to work it out. <?php include ('./populate.php'); ?> <?php $id=$_GET['id']; $val1=$_GET['year_2006']; if ($val1=="on") { $val1=1; } else { $val1=0; } $val2=$_GET['year_2007']; if ($val2=="on") { $val2=1; } else { $val2=0; } ?> <table width='1044' align="left" cellpadding="0" cellspacing="0" > <form action="TESTPHPCHECK.php?id=$id" method="POST" name='theForm' onsubmit=''> <input type="hidden" name="id" value="<?php echo $id; ?>"> <!--DWLayoutTable--> <td height="117" colspan="17" valign="top"><INPUT name="image" TYPE="image" class='forminput' value="Save" SRC="Buttons/NavBanner.gif" /> <h3><?php echo $row->current_name; ?></h3></td> <td width="11"> </td> <tr> <td height="13"></td> <td></td> <td colspan="5" rowspan="2" valign="top" class="edit">CAR Recd. </td> <td rowspan="2" align="center" valign="top"><?php include ('CAR_checkbox.php'); ?></td> <td></td> <td></td> <td></td> <td></td> </tr> </form> </table> TESTPHPCHECK.php <?php include("mysql_connect.php"); $val1 = $_POST['year_2006']; $val2 = $_POST['year_2007']; $id = $_POST['id']; $query17 = mysql_query("UPDATE car_checkbox SET year_2006='$val1' WHERE FileSerial='$id'") or die(mysql_error()); $query18 = mysql_query("UPDATE car_checkbox SET year_2007='$val2' WHERE FileSerial='$id'") or die(mysql_error()); ## The above statements run the whole query ## tyr adding some error checking if(!$query17){ echo "There is an error with query 17 <br>"; } else { echo "Query 17 was successful<br>"; } if(!$query18){ echo "There is an error with query 18 <br>"; } else { echo "Query 18 was successful<br>"; } #for more error checking you can try checking your posted variables with print_r($_POST); mysql_close($link); ?>
  10. Thanks for that! I would never have figured that out myself now the query updates successfully but it changes the values to 0 in the table even if the checkbox is checked. I will have a play around with some of the code maybe to get it working properly but at least the query is without errors now
  11. Thanks Micmania I have changed my field names as suggested but I'm still receiving the same error.
  12. Also when the 2006 checkbox is unchecked the error is different Incorrect integer value: '' for column '2006' at row 1
  13. Yes both 2006 and 2007 are fields in the database I will change them to something beginning with text as you advised. The backtick fixed the error message now I’m getting: Out of range value adjusted for column '2006' at row 1
  14. Thanks BlueSky, I'm getting a more detailed error now I have double checked my code and I don't see any simple errors. This occurs when the 2006 checkbox is checked You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2006='2006' WHERE FileSerial='AAC'' at line 1 This is the error when the 2006 checkbox is unchecked You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2006='' WHERE FileSerial='AAC'' at line 1
  15. Thanks again for your help. After making the changes you provided i get the following errors There is an error with query 17 There is an error with query 18 Array ( [id] => AAC [2007] => on [image_x] => 477 [image_y] => 40 ) Any ideas? I will try playing around some more with the code.
  16. Thanks ethought i modified my TESTPHPCheck.php file to (setting up db.php in the way you described): <?php include("db.php"); $query17 = mysql_query("UPDATE car_checkbox SET 2006='$val1' WHERE FileSerial='$id'", $db); $query18 = mysql_query("UPDATE car_checkbox SET 2007='$val2' WHERE FileSerial='$id'", $db); $result17 = mysql_query($query17); $result18 = mysql_query($query18); header("Location: TESTCheckbox.php?id=AAC"); mysql_close($link); ?> and also tried: <?php include("db.php"); $val1 = $_POST['2006']; $val2 = $_POST['2007']; $id = $_POST['id']; $query17 = mysql_query("UPDATE car_checkbox SET 2006='$val1' WHERE FileSerial='$id'", $db); $query18 = mysql_query("UPDATE car_checkbox SET 2007='$val2' WHERE FileSerial='$id'", $db); $result17 = mysql_query($query17); $result18 = mysql_query($query18); header("Location: TESTCheckbox.php?id=AAC"); mysql_close($link); ?> But the checkbox still does not update properly
  17. Hi All, I am trying to setup a basic Checkbox in PHP which saves to a MYSQL database. I have spent some time coding this myself and have reached a point where I am able to create a Checkbox which is populated from a MYSQL table. The issue is that when a user makes a change to the checkbox on the HTML page and clicks on the save button the change does not get saved correctly (there is no change at all). The Table is called car_checkbox and has the fields FileSerial (Primary Key), 2006 and 2007. I have one row in the table which contains the values AAC, 1, 0 The .php files I am using are TESTPHPCHECK.php which contains the code used for updating the Checkbox. TESTCheckbox.php which holds the form and table. CAR_Checkbox which is the code for the checkbox itself and populates the values stored in the table. I have had no trouble getting my dropdown menus, radio buttons and fields working on my pages. I am not sure what I am doing wrong here so if anyone has any solutions or advice it would be very much appreciated. Thanks in advance. TESTPHPCHECK.php <?php include ('./mysql_connect.php'); $val1 = $_POST['2006']; $val2 = $_POST['2007']; $id = $_POST['id']; $query17 = "UPDATE 'car_checkbox' SET 2006 = '$val1', 2007 = '$val2' WHERE FileSerial= '$id'"; $result17 = mysql_query($query17); header("Location: TESTCheckbox.php?id=AAC"); mysql_close($link); ?> TESTCheckbox.php <?php include ('./populate.php'); ?> <?php $id=$_GET['id']; $val1=$_GET['2006']; if ($val1=="on") { $val1=1; } else { $val1=0; } $val2=$_GET['2007']; if ($val2=="on") { $val2=1; } else { $val2=0; } ?> <table width='1044' align="left" cellpadding="0" cellspacing="0" > <form action="TESTPHPCHECK.php?id=$id" method="POST" name='theForm' onsubmit=''> <input type="hidden" name="id" value="<?php echo $id; ?>"> <!--DWLayoutTable--> <td height="117" colspan="17" valign="top"><INPUT name="image" TYPE="image" class='forminput' value="Save" SRC="Buttons/NavBanner.gif" /> <h3><?php echo $row->current_name; ?></h3></td> <td width="11"> </td> <tr> <td height="13"></td> <td></td> <td colspan="5" rowspan="2" valign="top" class="edit">CAR Recd. </td> <td rowspan="2" align="center" valign="top"><?php include ('CAR_checkbox.php'); ?></td> <td></td> <td></td> <td></td> <td></td> </tr> </form> </table> CAR_checkbox.php <?php include("mysql_connect.php"); $q="SELECT * FROM `car_checkbox` WHERE `FileSerial` = '$id'"; $r=mysql_query($q); $num=mysql_numrows($r); if ($num>0) { $val1=mysql_result($r,'0','2006'); $val2=mysql_result($r,'0','2007'); } else { //Else nothing is checked $val1=0; $val2=0; } //Show form echo "<input type='hidden' name='id' value='$id'>"; if ($val1=="0") { echo "<input name='2006' type='checkbox'>2006"; } else { echo "<input checked='checked' input name='2006' type='checkbox'>2006"; } if ($val2=="0") { echo "<input name='2007' type='checkbox'>2007"; } else { echo "<input checked='checked' input name='2007' type='checkbox'>2007"; } ?>
  18. Works fantastic! Thanks again MadTechie
  19. Hi MadTechie, thanks for your help. The full code I am using in the update.php file is: <?php include ('./mysql_connect.php'); $rrr_score = $_POST['rrr_score']; $bs_score = $_POST['bs_score']; $frs_score = $_POST['frs_score']; $fs_score = $_POST['fs_score']; $strength_summary = $_POST['strength_summary']; $ms_score = $_POST['ms_score']; $id = $_POST['id']; $query = "UPDATE company SET rrr_score = '$rrr_score', bs_score = '$bs_score', frs_score = '$frs_score', fs_score = '$fs_score', ms_score = '$ms_score', strength_summary = '$strength_summary' WHERE FileSerial= '$id'"; $result = mysql_query($query); header("Location: OrganiseIDASX.php?id={$_GET[$id]}"); mysql_close($link); ?> Using the code you provided returns the following in the URL: http://localhost:8888/OrganiseIDASX.php?id=
  20. Hi All, I have a form which when updated takes the user to an update screen. I was wondering if it was possible to redirect the user back to the screen where they entered the information and refresh the data basically just refreshing the page (and obviously updating the data in the database which is working fine). I have tried using some code and I can easily redirect back to the right page but I also need to have the 'id' selected so that it displays the recently updated record. Below is the code I attempted to use (i have tried everything I can think of). Any help would be appreciated. header('Location: OrganiseIDASX.php?id=echo $_GET[$id]');
  21. Thanks MadTechie I didn't really know what to search for. Thanks for your help
  22. Hi All, I'm relatively new to PHP and new to these forums. I am having trouble with a relatively simple task. I have a form split over multiple pages and I am trying to pass the id value between these pages in the URL. Currently the page looks like this: http://localhost:8888/OrganiseIDPLAN.php?id=AAO I have created a link to another page that looks like this: <a href="OrganiseIDASX.php?id="> I do not know what to make the id = to pick up the hidden field in which id is stored. I have tried everything I can think of. The data is not sensative though I was wondering if it may be easier to use sessions or cookies to do this. Thanks for your help
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.