Hello
I am making a simple page with one form.
I want to update the password for a user in a table in MySQL - there is only one user in the table.
The code DOES work. It really does update the table record, but once its updated, if succesfful I want it to redirect to another page... it brings out an error - I think its my result query
<?
if(isset($_GET['password']))
{
$password = $_GET['password'];
// Connect to MySQL
mysql_connect("localhost", "removed", "removed") or die(mysql_error());
mysql_select_db("table") or die(mysql_error());
// Update the database, where the admin ID is 1 and set the new password.
$query = 'UPDATE `table`.`admin` SET `password` = \''.$password.'\' WHERE `admin`.`id` = 1 LIMIT 1;';
$result = mysql_query($query) or die("Error: " . mysql_error());
// If the password has been updated - redirect to the login page
if(mysql_num_rows($result)==1)
{
// Details match, create the string
$ok=yes;
// Redirect for security reasons
print '<script type="text/javascript">window.location="login.php?newpass='.$ok.'";</script>';
} else {
// Error, the password cannot be reset
$err='Sorry the password has not been updated. Try again';
}
}
// Create the page
print "
<html>
<head>
<title>Admin Area Reset Password</title>
<link href='/table.css' rel='stylesheet' media='screen, projection' />
</head>
<body>
<div class='site'>
<div class='yellowbox'>Change Password to the Admin Area<br /> <a style='color:#000;' href='/admin/index.php?confirm=yes'>Back to Admin Area</a><strong>".$err."</strong></div>
<form action='changepass.php' method='GET'>
<p>new password:
<input type='password' name='password' size='20' />
</p>
<input type='submit' value='Change password' />
</form>
</div>
</body>
</html>";
?>
Error is
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /admin/newpass.php on line 18
Line 18
if(mysql_num_rows($result)==1)
Please can someone help?