spock9458 Posted September 23, 2009 Share Posted September 23, 2009 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, Quote Link to comment https://forums.phpfreaks.com/topic/175232-solved-need-help-with-update-query/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 23, 2009 Share Posted September 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175232-solved-need-help-with-update-query/#findComment-923587 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.