By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,847 Members | 2,285 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,847 IT Pros & Developers. It's quick & easy.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result,

P: 2
Heya, I get these 2 errors:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 20
You have not entered all the fields
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 34
Sorry You failed to enter the correct old password

I was wondering if anyone could help me, I have said where the lines are,
Please help,
[PHP]<?php
// Mysql
include ('mysql_connect.php');
//
$oldpass=$_POST['oldpass'];
$newpass=$_POST['newpass'];
$cnewpass=$_POST['cnewpass'];
$numrows = mysql_num_rows($res);
//
if (($oldpass==NULL)||( $newpass==NULL)||( $cnewpass==NULL)) {
echo "You have not entered all the fields";
}else{
}
//
if($newpass!=$cnewpass) {
echo "Passwords do not match";
} else {
}
//
$sql = "UPDATE users SET password = '".md5($newpass)."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass)."' ";
$res = mysql_query($sql,$dbc) or die (mysql_error());
$numrows = mysql_num_rows($res);
if ($numrows >0) {
echo "your password has been changed ";
} else {
echo "Sorry You failed to enter the correct old password";
}
mysql_query($sql,$dbc) or die (mysql_error());
?>[/PHP]
Jun 9 '07 #1
Share this Question
Share on Google+
4 Replies


P: 18
Heya, I get these 2 errors:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 20
You have not entered all the fields
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 34
Sorry You failed to enter the correct old password

I was wondering if anyone could help me, I have said where the lines are,
Please help,
[PHP]<?php
// Mysql
include ('mysql_connect.php');
//
$oldpass=$_POST['oldpass'];
$newpass=$_POST['newpass'];
$cnewpass=$_POST['cnewpass'];
$numrows = mysql_num_rows($res);
//
if (($oldpass==NULL)||( $newpass==NULL)||( $cnewpass==NULL)) {
echo "You have not entered all the fields";
}else{
}
//
if($newpass!=$cnewpass) {
echo "Passwords do not match";
} else {
}
//
$sql = "UPDATE users SET password = '".md5($newpass)."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass)."' ";
$res = mysql_query($sql,$dbc) or die (mysql_error());
$numrows = mysql_num_rows($res);
if ($numrows >0) {
echo "your password has been changed ";
} else {
echo "Sorry You failed to enter the correct old password";
}
mysql_query($sql,$dbc) or die (mysql_error());
?>[/PHP]
The function "mysql_num_rows()" returns the number of rows in the mysql result of a SELECT or SHOW statement.
An UPDATE statement does not return any rows. To find out if the update actually worked, or affected some rows in the database table, then use: "mysql_affected_rows()"

If you're doing an INSERT and want to know the id of the row the insert was made, use: "mysql_insert_id()"
Jun 9 '07 #2

epots9
Expert 100+
P: 1,351
on line 10, u test if the fields are empty echo a message, but then u still continue to trying to update the database. After the echo put [PHP]exit();[/PHP] so the script doesn't not continue, or change the header to redirect to another page (ie. the page with the fields).
Jun 9 '07 #3

P: 2
I have done what you have said but i still have the same error:
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/themepar/public_html/changepass.php on line 20
You have not entered all the fields
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/themepar/public_html/changepass.php on line 35
Sorry You failed to enter the correct old password
Thanks For your help anyway,
[PHP]<?php
session_start();
if (!isset($_SESSION['s_username'])) {
header("Location: login.php");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Change Pass</title>
</head>
<body>
<?php
// Mysql
include ('mysql_connect.php');
//
$oldpass=$_POST['oldpass'];
$newpass=$_POST['newpass'];
$cnewpass=$_POST['cnewpass'];
$numrows = mysql_affected_rows($res);
//
if (($oldpass==NULL)||( $newpass==NULL)||( $cnewpass==NULL)) {
echo "You have not entered all the fields";
}else{
exit();
}
//
if($newpass!=$cnewpass) {
echo "Passwords do not match";
} else {
}
//
$sql = "UPDATE users SET password = '".md5($newpass)."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass)."' ";
$res = mysql_query($sql,$dbc) or die (mysql_error());
$numrows = mysql_affected_rows($res);
if ($numrows >0) {
echo "your password has been changed ";
} else {
echo "Sorry You failed to enter the correct old password";
}
mysql_query($sql,$dbc) or die (mysql_error());
?>[/PHP]
Jun 9 '07 #4

pbmods
Expert 5K+
P: 5,821
Does mysql_connect.php set the value of $res? That won't work unless:
  • $res is global, or...
  • mysql_connect.php returns a value and you use the include statement to set the *local* variable $res:

mysql_connect.php:
Expand|Select|Wrap|Line Numbers
  1. return mysql_connect( ... );
  2.  
changepass.php:
Expand|Select|Wrap|Line Numbers
  1. $res = include('mysql_connect.php');
  2.  
Jun 10 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.