Jump to content

[SOLVED] mysql update not updating


sudsy1970

Recommended Posts

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>';
              }
           

         }      
?>
   

Link to comment
Share on other sites

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 ?

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.