Forum Moderators: coopster

Message Too Old, No Replies

Simple Change Password script problem

         

exotix

7:25 pm on Nov 18, 2007 (gmt 0)

10+ Year Member



hey im new to php and sql and im trying to make a simple change password script. So the user has logged in then want to change their password. I dont know how to tell sql what row to change the password in. In sql the password field is 'pass' and the username field is 'user'.

<?php
// Get the PHP file containing the DbConnector class
require_once('../includes/DbConnector.php');
require_once('../includes/Validator.php');
require_once("../includes/Sentry.php");

// Create an instance of DbConnector
$connector = new DbConnector();

// Check whether a form has been submitted. If so, carry on
if ($HTTP_POST_VARS){

// Validate the entries
$validator = new Validator();

// Check whether the validator found any problems
if ( $validator->foundErrors() ){
echo 'There was a problem with: <br>'.$validator->listErrors('<br>'); // Show the errors, with a line between each
}else{

// Create an SQL query (MySQL version)
// The 'addslashes' command is used 5 lines below for added security
// Remember to use 'stripslashes' later to remove them (they are inserted in front of any
// special characters

$insertQuery = "UPDATE $cmsusers (pass) VALUES ('$pass') WHERE 'id' = $user";

// Save the form data into the database
if ($result = $connector->query($insertQuery)){

// It worked, give confirmation
echo '<center><b>Password changed successfully</b></center><br>';

}else{

// It hasn't worked so stop. Better error handling code would be good here!
exit('<center>Sorry, there was an error saving to the database</center>');

}
}
}
?>

Thanks

PHP_Chimp

7:38 pm on Nov 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$insertQuery = "UPDATE $cmsusers (pass) VALUES ('$pass') WHERE 'id' = $user";

Is almost correct. Below is the syntax from the mysql manual -
UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
SET col_name1=expr1 [, col_name2=expr2 ...]
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]

So it should be -
$insertQuery = "UPDATE $cmsusers SET pass=$pass WHERE 'id' = $user";