jaybeeb Posted April 6, 2008 Share Posted April 6, 2008 Hi, Sorry my first post here is a question. Just started PHP Basically want to update a database using PHP, I have my form in my main html file and this is my PHP code. Keep getting the error "Update Query Failed" <?php if(isset($_POST['edit'])) { include 'config.php'; include 'opendb.php'; if(isset($_POST['edit'])) $User_Name = $_POST['User_Name']; $User_ID = $_POST['User_ID']; $Staff_ID = $_POST['Staff_ID']; $Problem = $_POST['Problem']; $Problem_ID = $_POST['Problem_ID']; $User_email = $_POST['User_email']; $Staff_email = $_POST['Staff_email']; $query = "UPDATE itsupport SET User_Name='$User_Name', Staff_ID=$Staff_ID, Problem='$Problem', Problem_ID=$Problem_ID,User_email='$User_email',Staff_email='$Staff_email' WHERE User_ID=$User_ID)"; mysql_query($query) or die ('Update Query Failed'); include 'closedb.php'; echo "Updated"; } else { ?> <form method="post"> <table width="400" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="100">User name</td> <td><input name="User_Name" type="text" id="User_Name"></td> </tr> <tr> <td width="100">User ID</td> <td><input name="User_ID" type="integer" id="User_ID"></td> </tr> <tr> <td width="100">Staff ID</td> <td><input name="Staff_ID" type="integer" id="Staff_ID"></td> </tr> <tr> <td width="100">Problem</td> <td><input name="Problem" type="text" id="Problem"></td> </tr> <tr> <td width="100">Problem_ID</td> <td><input name="Problem_ID" type="integer" id="Problem_ID"></td> </tr> <tr> <td width="100">User_email</td> <td><input name="User_email" type="text" id="User_email"></td> </tr> <tr> <td width="100">Staff_email</td> <td><input name="Staff_email" type="text" id="Staff_email"></td> </tr> <tr> <td width="100"> </td> <td><input name="add" type="submit" id="add" value="Update"></td> </tr> </table> </form> <?php } ?> </BODY> Link to comment https://forums.phpfreaks.com/topic/99888-updating-database-via-php/ Share on other sites More sharing options...
Catfish Posted April 6, 2008 Share Posted April 6, 2008 use mysql_error() to output the error that mysql is throwing when your query fails and post it here. Link to comment https://forums.phpfreaks.com/topic/99888-updating-database-via-php/#findComment-510822 Share on other sites More sharing options...
AndyB Posted April 6, 2008 Share Posted April 6, 2008 Avoid pointless error messages while testing. Have a useful error message - and post it here unless it points to an obvious solution: Change: mysql_query($query) or die ('Update Query Failed'); To: mysql_query($query) or die ('Update Query Failed. Error '. mysql_error(). ' with query '. $query); Link to comment https://forums.phpfreaks.com/topic/99888-updating-database-via-php/#findComment-510824 Share on other sites More sharing options...
jaybeeb Posted April 6, 2008 Author Share Posted April 6, 2008 Sorry about that, bit silly of me. Still dont understand this error though Update Query Failed. 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 with query UPDATE itsupport SET User_Name='James', Staff_ID=111, Problem='Screening', Problem_ID=999,User_email='[email protected]',Staff_email='[email protected]' WHERE User_ID=4554) Thanks Link to comment https://forums.phpfreaks.com/topic/99888-updating-database-via-php/#findComment-510826 Share on other sites More sharing options...
Catfish Posted April 6, 2008 Share Posted April 6, 2008 I dont know for sure but maybe enclose all your numeric field values (ProblemID, UserID etc) in single quotes? Oh wait. haha no scrap that. you have a closing bracket on the statement but no opening brackets. Link to comment https://forums.phpfreaks.com/topic/99888-updating-database-via-php/#findComment-510831 Share on other sites More sharing options...
CreactiveOnline Posted April 6, 2008 Share Posted April 6, 2008 Um... I think it's because on the line with your query $query = blah blah blah You have a ) at the end of it... I don't see a beginning one, and you don't need a beginning one anyways. See if that works Link to comment https://forums.phpfreaks.com/topic/99888-updating-database-via-php/#findComment-510833 Share on other sites More sharing options...
jaybeeb Posted April 6, 2008 Author Share Posted April 6, 2008 Um... I think it's because on the line with your query $query = blah blah blah You have a ) at the end of it... I don't see a beginning one, and you don't need a beginning one anyways. See if that works Well done buddy. Works a treat. Cheers. I really should have spotted that ??? THANKS Link to comment https://forums.phpfreaks.com/topic/99888-updating-database-via-php/#findComment-510836 Share on other sites More sharing options...
CreactiveOnline Posted April 6, 2008 Share Posted April 6, 2008 No problem - Happens to me all the time. With all that damn code it all starts to look the same doesn't it? Link to comment https://forums.phpfreaks.com/topic/99888-updating-database-via-php/#findComment-510840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.