hey everyone i\'m trying to write this script where a user can update his/her password and everything is in a function and is called through a switch statement. all of the functions work except for the function that updates the users password.

I was wondering if anyone could check out the code that i have written and see what might be wrong. i tested things out in the mysql command line and even though the script says it has updtaed the password if i try to debug it in the command line it shows that it hasnt updated.

here is the code:


function password_form() {

global $PHP_SELF;
global $userid, $username, $homepage;
global $dbhost, $dbusername, $dbuserpassword, $tablename, $default_dbname;


$connection = mysql_connect($dbhost, $dbusername, $dbuserpassword) or die (\"cannot access the $default_dbname\");
$db = mysql_select_db($default_dbname, $connection);
$query = \"SELECT * FROM $tablename WHERE username = \'$username\' AND userpassword = \'$userpassword\'\";
$result = mysql_query($query);

?>

echo \"<form name=\"password_form\" method=\"post\" action=\"<?php echo $PHP_SELF ?>\">
<input type=\"hidden\" name=\"action\" value=\"update_password\">
<input type=\"hidden\" name=\"username\" value=\"<?php echo $username ?>\">
<table width=\"300\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
	<tr>
		<td align=\"right\" class=\"mttext\">userid:</td>
		<td width=\"10\">&nbsp;</td>
		<td class=\"mttext\"><?php echo $username ?>
		  <br>
 		</td>
	 </tr>

	  <tr>
		<td align=\"right\" class=\"mttext\"><br>password:</td>
		<td>&nbsp;</td>
		<td><br>
	<input type=\"text\" name=\"userpassword\" class=\"fields\">
		</td>
	 </tr>


	  <tr>
		<td align=\"right\" class=\"mttext\"><br>retype password:</td>
		<td>&nbsp;</td>
		<td><br>
	<input type=\"text\" name=\"userpassword2\" class=\"fields\">
		</td>
	 </tr>

	 <tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	  </tr>

	  <tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>
			<input type=\"submit\" name=\"submit\" value=\"change password\" class=\"buttons\">
			<input type=\"reset\" name=\"reset\" value=\"clear\" class=\"buttons\">
 		 </td>
	 </tr>

	</table>
</form>

    function update_password() {

    global $PHP_SELF;
    global $userid, $username, $homepage;
    global $dbhost, $dbusername, $dbuserpassword, $tablename, $default_dbname, $userpassword, $userpassword2;
    
    if(empty($userpassword)) error_message("please enter a password");
    if(empty($userpassword2)) error_message("please make sure you retype the same password in both fields");
    
    $connection = mysql_connect($dbhost, $dbusername, $dbuserpassword) or die ("cannot access the $default_dbname");
    $db = mysql_select_db($default_dbname, $connection);
    $query = "UPDATE $tablename SET userpassword = password('$userpassword') WHERE username = '$username'";
    $result = mysql_query($query) or die ("cannot update your password");
    
    echo "your password has been changed";

    }

      password('$userpassword')???
      their is no such function as password?? is this a function you have made?

        Write a Reply...