Error syntax to update mysql data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geof
    New Member
    • Nov 2006
    • 3

    Error syntax to update mysql data

    Hi !
    this is my first post
    where is my error code in line 15 ($sql )

    <html>
    <head><title> update MySQL Data </title></head>
    <body bgcolor="#FFFFF F">

    <?

    $DBhost = "dbhost";
    $DBuser = "dbuser";
    $DBpass = "dbcode";
    $DBName = "dbname";
    $JANpass ="new code";

    $connect=mysql_ connect($DBhost ,$DBuser,$DBpas s) or die("Unable toconnect to database");
    mysql_select_db ("$DBName") or die("Unable to select database $DBName");
    $sql = 'UPDATE `jos_users` SET `password` = MD5( \'1q2w3e\' ) WHERE `username` = \'admin\';';
    mysql_query($sq l) or die ("not change your admin pass");
    echo="The new pass is $JANpass";
    mysql_close($co nnect)

    ?>
    </BODY></HTML>

    Thanks!
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Set your query within double quotes, your content must be within single quotes because you update a character type field. The single quotes are not part of the content, just a wrapper.
    Code:
    $sql = "UPDATE `jos_users` 
           SET `password` = MD5('1q2w3e' ) 
           WHERE `username` = 'admin'";
    Ronald :cool:

    Comment

    • geof
      New Member
      • Nov 2006
      • 3

      #3
      before send the post try for this but don' t work. and generated the upgrade code from phpmyAdmin and also doesn' t work.

      Thanks for your help
      Sorry for my English

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        The syntax of the UPDATE statement is correct. You'd better show us the error description that you get on the statement.

        But in order to do that you must do what you should have done to begin with: it is a good custom to 'catch' the error messages you receive after any command, whether MySQL or file or whatever, that can return an error.

        So you must change your statement like shown here. I suggest you do the same for the other 'non-captured' MySQL statements in your code.
        [php]mysql_query($sq l)
        or die ("not change your admin pass, error: ". mysql_error());
        [/php]
        Ronald :cool:

        Comment

        • geof
          New Member
          • Nov 2006
          • 3

          #5
          Ronald

          T H A N K S !!!
          Solved

          The full correct code is

          <html>
          <head><title> update MySQL Data </title></head>
          <body bgcolor="#FFFFF F">

          <?
          /* declare some relevant variables */
          $DBhost = "dbhost";
          $DBuser = "dbuser";
          $DBpass = "dbcode";
          $DBName = "dbname";
          $JANpass ="new code";

          $condb=mysql_co nnect($DBhost,$ DBuser,$DBpass) or die("Unable to connect to database".mysql _error());
          mysql_select_db ("$DBName") or die("Unable to select database $DBName,error:" .mysql_error()) ;
          $sql = "UPDATE `jos_users`
          SET `password` = MD5('$JANpass' )
          WHERE `username` = 'admin'";
          mysql_query($sq l) or die ("not change your admin pass,error:".my sql_error());
          echo "The new admin pass is '$JANpass'";
          mysql_close($co ndb)

          ?>
          </BODY></HTML>

          Comment

          Working...