Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Need help with UPDATE in Prepared Statement

    I am having trouble with the syntax of an UPDATE in my Prepared Statement.

    Here is what I have...
    PHP Code:
        // Build query.
        
    $r "UPDATE member
            SET pass = SHA1('$newPass')
            WHERE email=?"

    I started thinking that is incorrect because of $newPass...

    Should it maybe be...
    PHP Code:
        // Build query.
        
    $r "UPDATE member
            SET pass = ?
            WHERE email=?"
    ;

        
    // Prepare statement.
        
    $stmt2 mysqli_prepare($dbc$r);

        
    // Bind variable.
        
    mysqli_stmt_bind_param($stmt2'ss'$emailSHA1('$newPass')); 
    I really have no clue on this one?!



    Debbie
    Last edited by doubledee; 09-08-2011 at 05:37 AM.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Give this a shot:
    PHP Code:
    // Build query
    $r '
        UPDATE `member`
        SET `pass` = SHA1( ? )
        WHERE `email` = ?
        LIMIT 1
    '
    ;

    // Prepare statement
    $stmt2 mysqli_prepare$dbc$r );

    // Bind variable names
    mysqli_stmt_bind_param$stmt2'ss'$newPass$email );

    // Assign variables
    // For this example, we're grabbing posted data
    $email   $_POST['email'];
    $newPass $_POST['newPass'];

    // Execute statement
    mysqli_stmt_execute$stmt2 );

    // How many rows were affected?
    // Because of the `LIMIT 1`, it will be either `0` or `1`
    $affected_rows mysqli_stmt_affected_rows$stmt2 ); 
    Last edited by kbluhm; 09-08-2011 at 01:55 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •