jaybeeb Posted October 14, 2008 Share Posted October 14, 2008 Having problems trying to update a sql table. The first part of code is where the user edits the actual data. It brings the data in just fine i.e when this page opens the data to be edited is in the correct text boxes, but when data is changed and update is clicked, it goes back to the table gives no errors - but the data has not been edited. Any ideas? Thanks in advance, <?php require_once 'library/db.php'; //require_once 'error.php'; if (!($conn = mysql_connect('localhost', 'root', ''))) { showError(); } if (!(mysql_select_db('emp_agency', $conn))) { showError(); } $a = $_GET['id']; if (!($result = mysql_query("select * from jobs where id = '$a'", $conn))) { $conn = mysql_connect('localhost', 'root', '') OR DIE (mysql_error()); } $row =mysql_fetch_array($result); mysql_close($conn); ?> <html> <body> <form action="saveedit.php" method="post"> <table border="0"> <tr> <td> ID </td> <td> <?php echo $row['id']; ?> <input type="hidden" name="User_ID" value = "<?php echo $row['id']; ?>"> </td> </tr> <tr> <td> Job Description </td> <td> <input type="text" name="job_description" value = "<?php echo $row['job_description']; ?>"> </td> </tr> <tr> <td> Experience Required </td> <td> <input type="integer" name="experience_required" value = "<?php echo $row['experience_required']; ?>"> </td> </tr> <tr> <td> Contact </td> <td> <input type="text" name="contact" value = "<?php echo $row['contact']; ?>"> </td> </tr> </table> <input type="submit" value="Update"> </form> </body> </html> <?php require_once 'library/db.php'; //require_once 'error.php'; $User_ID = $_GET['id']; if (!($conn = mysql_connect('localhost', 'root', ''))) { showError(); } if (!(mysql_select_db('itsupport', $conn))) { showError(); } if (!($result = mysql_query("UPDATE jobs SET job_description=\"$_POST[job_description]\", experience_required=\"$_POST[experience_required]\", contact=\"$_POST[contact]\" WHERE id=\"$_POST[id]\"",$conn))) { $conn = mysql_connect('localhost', 'root', '') OR DIE (mysql_error()); } mysql_close($conn); include 'employerpage.php'; ?> Link to comment https://forums.phpfreaks.com/topic/128411-sql-update/ Share on other sites More sharing options...
revraz Posted October 14, 2008 Share Posted October 14, 2008 Use mysql_error() after your query to see why it's failing. Your query is incorrect Link to comment https://forums.phpfreaks.com/topic/128411-sql-update/#findComment-665335 Share on other sites More sharing options...
Barand Posted October 14, 2008 Share Posted October 14, 2008 It's better to connect to the db before calling the query. Link to comment https://forums.phpfreaks.com/topic/128411-sql-update/#findComment-665344 Share on other sites More sharing options...
jaybeeb Posted October 14, 2008 Author Share Posted October 14, 2008 Use mysql_error() after your query to see why it's failing. Your query is incorrect Sorry , bit of a PHP amateur. I tried putting echo mysql_error(); after the query but doesnt display an error. Also, what is incorrect about my query? Thanks for the help. It's better to connect to the db before calling the query. require_once 'library/db.php'; is connecting to the db <?php // database configuration $db = array('Server' => 'localhost', 'user' => 'root', 'password' => '', database => 'emp_agency'); ?> Thanks Link to comment https://forums.phpfreaks.com/topic/128411-sql-update/#findComment-665348 Share on other sites More sharing options...
Barand Posted October 14, 2008 Share Posted October 14, 2008 OK Link to comment https://forums.phpfreaks.com/topic/128411-sql-update/#findComment-665422 Share on other sites More sharing options...
jaybeeb Posted October 15, 2008 Author Share Posted October 15, 2008 any ideas anyone? Link to comment https://forums.phpfreaks.com/topic/128411-sql-update/#findComment-666354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.