sudsy1970 Posted November 25, 2008 Share Posted November 25, 2008 hi am back again !! can anyone please tell me why my data will not update as it is driving me mad. The code runs ok but when i check the mysql database it has not been updated. <?php session_start(); $User= mysql_real_escape_string(trim($_POST['Username'])); $Firstname = mysql_real_escape_string(trim($_POST['Firstname'])); $Surname = mysql_real_escape_string(trim($_POST['Surname'])); $Email = mysql_real_escape_string(trim($_POST['Email'])); $Password1 = mysql_real_escape_string(trim($_POST['Password1'])); $errors = array(); // Email verification amended from http://www.plus2net.com/php_tutorial/php_email_validation.php if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)) { $errors[] = 'This is not a valid email address'; } if (strlen($Password1) < 6) { $errors[] = "Your password must be 6 characters"; } if (count($errors) == 0) { // Connect to mysql $dbServer = mysql_connect("localhost", "0274148", "8lgn62"); mysql_select_db("db0274148", $dbServer); } if (!$dbServer) { echo "Failed to connect to MySQL"; exit; } else { echo "connected to the database<br>"; } // updates the data into the database $sql = "UPDATE users SET (firstname ='$Firstname',surname='$Surname',email='$Email',password='$Password1' WHERE username='$User')"; mysql_query($sql); echo "Congratulations your details have been updated<br>"; echo ("<a href=\"main.php\">Back to Main Page</a>"); // will show if there has been an error and tell what error it is if (mysql_error()) { mysql_error(); } else { echo 'The following errors were found:<ul>'; foreach ($errors as $error) { echo "<li>$error</li><br>"; echo '</ul>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/134284-solved-mysql-update-not-updating/ Share on other sites More sharing options...
DeanWhitehouse Posted November 25, 2008 Share Posted November 25, 2008 Don't expect help before you have even tried debugging. Add die statements to your queries and your connections then tell us if there are any errors. Quote Link to comment https://forums.phpfreaks.com/topic/134284-solved-mysql-update-not-updating/#findComment-699069 Share on other sites More sharing options...
sudsy1970 Posted November 26, 2008 Author Share Posted November 26, 2008 if i knew about die statements i would have probably used them, have been trying to get this working for two hours, with lots of errors that i have manged to correct, only to find now when it runs through it does not actually update the table. have also looked at the w3 school and believe it conforms to how they say. What else can i add in order to get any error statements ? Quote Link to comment https://forums.phpfreaks.com/topic/134284-solved-mysql-update-not-updating/#findComment-699077 Share on other sites More sharing options...
DeanWhitehouse Posted November 26, 2008 Share Posted November 26, 2008 On all queries put or die(mysql_error()); like below mysql_query() or die(mysql_error()); //some people like to put a way to reference that query as well and to the top of the page put error_reporting(E_ALL); and edit: ini_set("display_errors",true); I think that is now right^^ Quote Link to comment https://forums.phpfreaks.com/topic/134284-solved-mysql-update-not-updating/#findComment-699081 Share on other sites More sharing options...
sudsy1970 Posted November 26, 2008 Author Share Posted November 26, 2008 Right thank you, did that and got: Notice: Use of undefined constant ’display_errors’ - assumed '’display_errors’' in /home/stud/0/0274148/public_html/Assignment/updatedetails.php on line 3 Notice: Use of undefined constant ‘On’ - assumed '‘On’' in /home/stud/0/0274148/public_html/Assignment/updatedetails.php on line 3 connected to the database You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(firstname ='anthony',surname='suddes',email='A.Suddes@wlv.ac.uk Quote Link to comment https://forums.phpfreaks.com/topic/134284-solved-mysql-update-not-updating/#findComment-699085 Share on other sites More sharing options...
DeanWhitehouse Posted November 26, 2008 Share Posted November 26, 2008 $sql = "UPDATE users SET firstname ='$Firstname',surname='$Surname',email='$Email',password='$Password1' WHERE username='$User'"; mysql_query($sql); try that Quote Link to comment https://forums.phpfreaks.com/topic/134284-solved-mysql-update-not-updating/#findComment-699086 Share on other sites More sharing options...
sudsy1970 Posted November 26, 2008 Author Share Posted November 26, 2008 Cannot believe it was as simple as brackets. Thank you very much for your help. Those error statements are very handy too! Quote Link to comment https://forums.phpfreaks.com/topic/134284-solved-mysql-update-not-updating/#findComment-699094 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.