Jump to content
lauralee

UPDATE not working

Recommended Posts

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(); } }

Share this post


Link to post
Share on other sites

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 by thescientist

Share this post


Link to post
Share on other sites

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);

Share this post


Link to post
Share on other sites

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(); } }

Share this post


Link to post
Share on other sites

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 by thescientist

Share this post


Link to post
Share on other sites

I made the changes that you suggested with no result. I still receive no error, and no update takes place.

Share this post


Link to post
Share on other sites

show us your code then

Share this post


Link to post
Share on other sites

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(); } }

Share this post


Link to post
Share on other sites

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 by thescientist

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...