Source code example for Web Database Applications
Unless otherwise stated, the source code distributed with this book can be
redistributed in source or binary form so long as an acknowledgment appears
in derived source files.
The citation should list that the code comes from Hugh E.
Williams and David Lane, "Web Database Application with PHP and MySQL"
published by O'Reilly & Associates.
This code is under copyright and cannot be included in any other book,
publication, or educational product without permission from O'Reilly &
No warranty is attached; we cannot take responsibility for errors or fitness
// Update a password in a users table
// Use the first two characters of the
// username as a salt
$salt = substr($username, 0, 2);
// Create the encrypted password
$stored_password = crypt($password, $salt);
// Update the user row
SET password = '$stored_password'
WHERE user_name = '$username'";
// Execute the UPDATE
$result = @ mysql_query ($update_query, $connection)