lauralee Posted June 18, 2013 Share Posted June 18, 2013 Can anyone find the problem with my code? I have used this code to update a table of contact information in my database, but for some reason, this same structure doesn't work for updating a fee schedule table. I don't get any kind of error, it just won't update the table. echo '<form action=" " method="post">';echo '<table class="contactlist"><tr><caption>FEE SCHEDULE</caption></tr><tr><th>FOR:</th><th>TYPE<th>DESCRIPTION</th><th>AMOUNT</th><th>ORDER</th></tr>'; while ($rw = @mysql_fetch_array($rslt)) {echo '<input type="hidden" name="fee_id" value = "' . $rw['fee_id'] . '" />';echo '<tr><td><input type="text" name="fee_title" value = "' . $rw['fee_title'] . '" size="35" /></td>';echo '<td><input type="text" name="fee_name" rows="5" cols="20" value = "' . htmlspecialchars($rw['fee_name'], ENT_QUOTES, 'UTF-8') . '" size="30" /></td>';echo '<td><input type="text" name="fee_description" value = "' . htmlspecialchars($rw['fee_description'], ENT_QUOTES, 'UTF-8') . '" size="20" /></td>';echo '<td><input type="text" name="fee_amount" value="' . $rw['fee_amount'] . '" size="25" /></td>';echo '<td><input type="text" name="fee_order" value="' . $rw['fee_order'] . '" size="5" /></td>';echo '<td><input type="submit" name="action" value="Edit" /></td></tr>';echo '</form>';} echo '</table>'; if (isset($_POST['action']) and $_POST['action'] =='Edit'){ $fee_id = $_POST['fee_id']; $fee_title = $_POST['fee_title']; $fee_name = $_POST['fee_name'];$fee_description = $_POST['fee_description']; $fee_amount = $_POST['fee_amount']; $fee_order = $_POST['fee_order'];$fee_title= mysql_real_escape_string($fee_title);$fee_description= mysql_real_escape_string($fee_description); $fee_name= mysql_real_escape_string($fee_name);$fee_order= mysql_real_escape_string($fee_order);$sql = "UPDATE fee_schedule SET fee_id = '$fee_id', fee_title = '$fee_title', fee_name = '$fee_name', fee_description = '$fee_description', fee_amount = '$fee_amount', fee_order = '$fee_order' WHERE fee_id ='$fee_id'"; if (!@mysql_query($sql)) { echo '<p>Error updating fee schedule: ' . mysql_error() . '</p>'; exit(); } } Link to comment Share on other sites More sharing options...
thescientist Posted June 18, 2013 Share Posted June 18, 2013 (edited) the reason you probably aren't getting any errors, is because you are suppressing errors when you include the @ sign if (!@mysql_query($sql)) { echo '<p>Error updating fee schedule: ' . mysql_error() . '</p>'; exit();} Edited June 18, 2013 by thescientist Link to comment Share on other sites More sharing options...
justsomeguy Posted June 18, 2013 Share Posted June 18, 2013 You should also have something like this at the top, to make sure that all error messages will get printed: ini_set('display_errors', 1);error_reporting(E_ALL); You may want to remove that for a live site, but when you're testing you need to have all errors enabled. You can send them to an error log instead of printing them in the browser if you want to do that too. If you want to disable all error suppression operators, you can also use scream: ini_set('scream.enabled', 1); Link to comment Share on other sites More sharing options...
lauralee Posted June 19, 2013 Author Share Posted June 19, 2013 Thanks. But my problem is that the coding I use on one page works fine, but the other one doesn't, although they seem to be identical, just the names are different. Below is the update that works. Can you find a difference in the one I posted earlier that would explain why this one works and the other one doesn't? I can't find the problem in the UPDATE code that I posted earlier. if (isset($_POST['action']) and $_POST['action'] =='Edit'){ $contacts_id = $_POST['contacts_id']; $contacts_first_name = $_POST['contacts_first_name']; $contacts_last_name = $_POST['contacts_last_name'];$contacts_department = $_POST['contacts_department'];$contacts_title = $_POST['contacts_title']; $contacts_email = $_POST['contacts_email']; $contacts_order = $_POST['contacts_order']; $publish = $_POST['publish']; $contacts_first_name= mysql_real_escape_string($contacts_first_name); $contacts_last_name= mysql_real_escape_string($contacts_last_name); $contacts_email= mysql_real_escape_string($contacts_email); $sql = "UPDATE contacts SET contacts_first_name = '$contacts_first_name', contacts_last_name = '$contacts_last_name', contacts_department = '$contacts_department', contacts_title = '$contacts_title', contacts_email = '$contacts_email', contacts_order = '$contacts_order', publish = '$publish' WHERE contacts_id ='$contacts_id'"; if (!@mysql_query($sql)) { echo '<p>Error updating contacts: ' . mysql_error() . '</p>'; exit(); } } Link to comment Share on other sites More sharing options...
thescientist Posted June 19, 2013 Share Posted June 19, 2013 (edited) we've already told you how to address the issue. You're not allowing for errors to be shown to you. You don't have to guess. Read what we've been saying, and then the errors will tell you what's wrong. Edited June 19, 2013 by thescientist Link to comment Share on other sites More sharing options...
lauralee Posted June 19, 2013 Author Share Posted June 19, 2013 I made the changes that you suggested with no result. I still receive no error, and no update takes place. Link to comment Share on other sites More sharing options...
thescientist Posted June 19, 2013 Share Posted June 19, 2013 show us your code then Link to comment Share on other sites More sharing options...
justsomeguy Posted June 19, 2013 Share Posted June 19, 2013 Print out the SQL query before you update and paste what it shows. Link to comment Share on other sites More sharing options...
lauralee Posted June 25, 2013 Author Share Posted June 25, 2013 Below is the code with the suggested changes. Still no UPDATE takes place. I use the same code to UPDATE another database table (with different field names) and it works. So I must be missing something here. if (isset($_POST['action']) and $_POST['action'] =='Edit'){ $fee_id = $_POST['fee_id']; $fee_title = $_POST['fee_title']; $fee_name = $_POST['fee_name'];$fee_description = $_POST['fee_description']; $fee_amount = $_POST['fee_amount']; $fee_order = $_POST['fee_order'];$fee_title= mysql_real_escape_string($fee_title);$fee_description= mysql_real_escape_string($fee_description); $fee_name= mysql_real_escape_string($fee_name);$fee_order= mysql_real_escape_string($fee_order);$sql = "UPDATE fee_schedule SET fee_id = '$fee_id', fee_title = '$fee_title', fee_name = '$fee_name', fee_description = '$fee_description', fee_amount = '$fee_amount', fee_order = '$fee_order' WHERE fee_id ='$fee_id'";ini_set('display_errors', 1);error_reporting(E_ALL); if (!mysql_query($sql)) { echo '<p>Error updating fee schedule: ' . mysql_error() . '</p>'; exit(); } } Link to comment Share on other sites More sharing options...
thescientist Posted June 25, 2013 Share Posted June 25, 2013 (edited) how are you confirming the code is even being run? if (isset($_POST['action']) and $_POST['action'] =='Edit'){ are you sure the code has even made it into the if block? Edited June 25, 2013 by thescientist Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now