Is this the correct Code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cheryl
    New Member
    • Nov 2006
    • 9

    Is this the correct Code?

    I am building a website with PHP and MySQL server. I have created a table named log-in with an attribute of username and password. The website has only one administrator. The administrator shall update his password by changing his own password. My SQL code to update is

    $query = "UPDATE INTO login (password) values ('$newpassword' )";
    mysql_query ($query) or die ("");


    This code does not work.....Is this the correct format?
    kindly help
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Originally posted by cheryl
    I am building a website with PHP and MySQL server. I have created a table named log-in with an attribute of username and password. The website has only one administrator. The administrator shall update his password by changing his own password. My SQL code to update is

    $query = "UPDATE INTO login (password) values ('$newpassword' )";
    mysql_query ($query) or die ("");

    This code does not work.....Is this the correct format?
    kindly help
    The correct format is
    Code:
    $query = "UPDATE login password='$newpassword' WHERE username='$username'";
    $result = mysql_query ($query) 
      or die ("UPDATE failed: ".mysql_error());
    Note that I have added the WHERE clause in the statement. If you do NOT use this clause the statement will update all password fields in all rows of table 'login'!

    Ronald :cool:

    Comment

    • kamill
      New Member
      • Dec 2006
      • 71

      #3
      if you are not using username in your table then you can use like this otherwise you can follow like ronald..
      [PHP]$query = "UPDATE login password='$newp assword' WHERE password='$oldp assword'";[/PHP]

      Comment

      Working...