473,322 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 7815
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

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

Similar topics

2
by: Noel Wood | last post by:
Hello I keep getting a warning ... Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in "name of my php file" when I run this query.... SELECT Menu_Item,...
2
by: Willem Berendsen | last post by:
Hello, I setting up my mysql-server and php on IIS6 and it works almost fine. But I got the next error: Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in...
3
by: Pratchaya | last post by:
Hi Everyone ============================================================== About PHP::: Error/Problem PHP Warning: mysql_fetch_array():...
7
by: Dejan | last post by:
Hi Sorry for my terreble english. On my local (win) comp i have apache+mysql+php 4.05 I'm counting rows using mysql_num_rows function, and everything works fine. When i upload php file on...
3
by: petemaxi | last post by:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\tockholes\includes\menu.inc.php on line 9 <div class="left"> <div class="menu">...
2
by: techjohnny | last post by:
Error: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/jplane/certcent/phpweb/quiz/index.php on line 20 Warning: mysql_num_rows(): supplied argument is...
1
by: lsmamadele | last post by:
I am getting the following error messages in my search: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mamadele/public_html/BESTPLAYS/search.php on...
4
by: fisherd | last post by:
When i run this code, i keep getting this message; Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\checklogin.php on line 26 i use this code to...
2
by: poreko | last post by:
I am connecting to my database using Object oriented PHP. My query is returning results but at the end of my table,at the bottom of the page I keep having this error when I run my program: Warning:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.