timmah1 Posted March 27, 2012 Share Posted March 27, 2012 I cannot figure out for the life of me why this isn't updating the database if(isset($_POST['update1'])){ $id1 = mysql_real_escape_string($_POST['id1']); $parentid = mysql_real_escape_string($_POST['parentid']); $title = mysql_real_escape_string($_POST['title']); $result1 = mysql_query("UPDATE subcat SET parentid='$parentid', name='$title' WHERE id='$id1'") or die(mysql_error()); echo "<p>Sub Category <b><em>$title</em></b> has been updated</p>"; } and here is the form <form action="page-subs.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <input name="id1" type="hidden" value="<?php echo $id; ?>"> <table width="100%" border="0" cellspacing="0" cellpadding="5" class='table_border'> <tr> <td align="left" valign="top">Brand</td> <td align="left" valign="top"><input name="title" type="text" id="title" value="<?php echo $title; ?>" /></td> </tr> <tr> <td>Category</td> <td><select name="parentid" id="parentid" > <option>Please Select</option> <option value="<?php echo $parent; ?>" <?php if($parent=="1") { echo "selected"; }?>>Blubird</option> <option value="<?php echo $parent; ?>" <?php if($parent=="2") { echo "selected"; }?>>Carpenter</option> <option value="<?php echo $parent; ?>" <?php if($parent=="3") { echo "selected"; }?>>Thomas</option> <option value="<?php echo $parent; ?>" <?php if($parent=="4") { echo "selected"; }?>>Wayne</option> <option value="<?php echo $parent; ?>" <?php if($parent=="5") { echo "selected"; }?>>Inter-Amtran</option> <option value="<?php echo $parent; ?>" <?php if($parent=="6") { echo "selected"; }?>>Misc</option> </select></td> </tr> <tr> <td> </td> <td><input type="submit" name="update1" id="update1" value="Update Sub Catgegory" /></td> </tr> </table> </form> I get this error 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 '' at line 1 Can anybody see what is wrong?? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 27, 2012 Share Posted March 27, 2012 You need to investigate what the actual query statement is that is failing. Form the query statement in a php variable and output it as part of the die() statement so that you can see exactly what the whole query is and exactly what is at the point where the error is being reported. Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331680 Share on other sites More sharing options...
timmah1 Posted March 27, 2012 Author Share Posted March 27, 2012 I understand. Tell me something, why when I comment everything out if(isset($_POST['update1'])){ //$id1 = mysql_real_escape_string($_POST['id1']); //$parentid = mysql_real_escape_string($_POST['parentid']); //$title = mysql_real_escape_string($_POST['title']); //$result1 = mysql_query("UPDATE subcat SET parentid='$parentid', name='$title' WHERE id='$id1'") //or die(mysql_error($result1)); echo "<p>Sub Category <b><em>$title</em></b> has been updated</p>"; } I get the same error? Sub Category has been updated 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 '' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331684 Share on other sites More sharing options...
Jessica Posted March 27, 2012 Share Posted March 27, 2012 Is that the entire code? Did you remember to save and upload it if you need to do so? Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331686 Share on other sites More sharing options...
timmah1 Posted March 27, 2012 Author Share Posted March 27, 2012 Is that the entire code? Did you remember to save and upload it if you need to do so? Are you asking me if I saved and uploaded the file? Really? Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331688 Share on other sites More sharing options...
Jessica Posted March 27, 2012 Share Posted March 27, 2012 Is that the entire code? Did you remember to save and upload it if you need to do so? Are you asking me if I saved and uploaded the file? Really? No, you're imagining it. Why do YOU think if you comment out a section of code it would still execute? Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331690 Share on other sites More sharing options...
timmah1 Posted March 27, 2012 Author Share Posted March 27, 2012 Is that the entire code? Did you remember to save and upload it if you need to do so? Are you asking me if I saved and uploaded the file? Really? No, you're imagining it. Why do YOU think if you comment out a section of code it would still execute? No, I don't think it would execute, I was just testing something out, and obviously that wasn't working. I'm was trying to see if the $_POST was correct, and I'm seeing that it's not, if I'm getting the same error Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331692 Share on other sites More sharing options...
Jessica Posted March 27, 2012 Share Posted March 27, 2012 *headdesk*. I feel sort of justified in my question now. good luck. Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331696 Share on other sites More sharing options...
timmah1 Posted March 27, 2012 Author Share Posted March 27, 2012 *headdesk*. I feel sort of justified in my question now. good luck. Wow! Thanks jesirose. That's just the kind of help I was looking for coming to a Help forum. Your inspiring words has helped drastically! Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331698 Share on other sites More sharing options...
Jessica Posted March 27, 2012 Share Posted March 27, 2012 You're welcome! Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331701 Share on other sites More sharing options...
samshel Posted March 27, 2012 Share Posted March 27, 2012 debuggin more is the only option. var_dump($_POST); move query to a variable $strSql = "UPDATE subcat SET parentid='$parentid', name='$title' WHERE id='$id1'"; echo $strSql; $result1 = mysql_query($strSql) or die(mysql_error()); From the error it looks like one of the post variables are not set correctly. Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331704 Share on other sites More sharing options...
timmah1 Posted March 27, 2012 Author Share Posted March 27, 2012 Thank you samshel, the db is updating, but it still shows the error UPDATE subcat SET parentid='2', name='MISCELLANEOUS REPAIR PARTS' WHERE id='103' array(4) { ["id1"]=> string(3) "103" ["title"]=> string(26) "MISCELLANEOUS REPAIR PARTS" ["parentid"]=> string(1) "2" ["update"]=> string(20) "Update Sub Catgegory" } Sub Category MISCELLANEOUS REPAIR PARTS has been updated 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 '' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331709 Share on other sites More sharing options...
samshel Posted March 27, 2012 Share Posted March 27, 2012 If the var dump is of $_POST then the variables names are not matching. you are checking for $_POST['update1'] and $_POST has update. Also is the code you posted only code with query in your page? Is there any query below the code which might be breaking? Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331714 Share on other sites More sharing options...
samshel Posted March 27, 2012 Share Posted March 27, 2012 since you are getting this error even if you comment out the code...I am getting a feeling that this is not what is breaking.. There may be some other code below this which is breaking...just a guess. Quote Link to comment https://forums.phpfreaks.com/topic/259831-why-wont-this-update/#findComment-1331720 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.