472,139 Members | 1,338 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

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

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
4 7644
bucabay
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
1,351 Expert 1GB
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
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
5,821 Expert 4TB
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.

Similar topics

2 posts views Thread by Willem Berendsen | last post: by
7 posts views Thread by Dejan | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.