Jump to content

Recommended Posts

I am trying a very simple UPDATE query that I learned from an online tutorial.  I have tried to implement an error handling method to see what the problem is, but there is no indication of the error when I run the query.  Here is the code:

 

<?php

   function showerror(  )
   {
      die("Error " . mysql_errno(  ) . " : " . mysql_error(  ));
   }

if ($_POST['submit'] == "Update") // Check for _POST info. 
{ 
//DB CONNECTION INFO

mysql_connect("localhost", "user",
"password") or die('Cannot connect to the database because: ' . mysql_error());

mysql_select_db ("members");

$ud_cont_name=$_POST['ud_cont_name'];
$ud_cont_email=$_POST['ud_cont_email'];
$ud_cont_phone=$_POST['ud_cont_phone'];
$ud_cont_direct=$_POST['ud_cont_direct'];
$ud_cont_cell=$_POST['ud_cont_cell'];
$ud_cont_fax=$_POST['ud_cont_fax'];
$ud_id=$_POST['ud_id'];

$query="UPDATE contact SET cont_name='$ud_cont_name', cont_email='$ud_cont_email', cont_phone='$ud_cont_phone', cont_direct='$ud_cont_direct', cont_cell='$ud_cont_cell', cont_fax='$ud_cont_fax' WHERE id='$ud_id'";

mysql_query($query);
echo "Record Updated";
mysql_close();
}

else {
echo "Problems...<br>" . showerror(  );

}
?>

 

The only thing that shows up when this query runs is "Error:"  No other info is given, and the record is not updated.  I'm sure there is a problem with my code, but I have gone over it several times and I cannot find it.  Please help if you can.

 

Thanks,

Link to comment
https://forums.phpfreaks.com/topic/175232-solved-need-help-with-update-query/
Share on other sites

Your else {} statement that is outputting the error information is part of this if() test -

 

if ($_POST['submit'] == "Update")

 

So, anytime the $_POST variable does not have that value, you will get just "Error:" because none of the mysql_ statements have even been executed.

 

You should actually have the existing else {} statement be part of an if() that you put around the mysql_query() statement.

 

But your actual problem appears to be that your form is not setting the $_POST variable as you expect.

 

Have you echoed $_POST['submit'] to see what it actually contains? Beyond that you would need to post your form for anyone here to be able to help with why it is not sending the expected value.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.