•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,643 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,774 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 100369 | Replies: 43
![]() |
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
#21
May 10th, 2007
•
•
Join Date: May 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
#22
May 10th, 2007
•
•
Join Date: Jul 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
#23
Jul 1st, 2007
Ok maybe someone can see something im missing (its driving me in sane)
this returns:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/worldjam/wjm.php on line 16
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
what am I doing wrong?
Thanks in advanced
Tom
$query = mysql_query("UPDATE user SET meso='1' WHERE uid='$this->user'");
$nrows = mysql_num_rows($query);
$ret = mysql_query($query) or die(mysql_error()); this returns:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/worldjam/wjm.php on line 16
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
what am I doing wrong?
Thanks in advanced
Tom
Last edited by theflyingtom : Jul 1st, 2007 at 11:41 pm.
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
#24
Jul 2nd, 2007
•
•
•
•
Ok maybe someone can see something im missing (its driving me in sane)
$query = mysql_query("UPDATE user SET meso='1' WHERE uid='$this->user'"); $nrows = mysql_num_rows($query); $ret = mysql_query($query) or die(mysql_error());
this returns:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/worldjam/wjm.php on line 16
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
what am I doing wrong?
Thanks in advanced
Tom
Try storing your query in a string. like the following.
$sql = "SELECT x FROM y";
$ret = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($ret);
theres an error in your query, which is not returning a valid result resource to your $query variable.
That is why your num_rows function is giving error.
Put your query into a string, and echo the string, so you can see if your variables are working ok.. and so on.
If you're still having bother, tell us what your query echo displays.
Cheers.
Drag.
Last edited by dr4g : Jul 2nd, 2007 at 5:46 am.
GardCMS :: Open Source CMS :: Gardcms.org
•
•
Join Date: Jul 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
#25
Jul 4th, 2007
<?php
// First set the form strings, which will be displayed
//in various cases below
$thisfile = $_SERVER['PHP_SELF']; //Have to set this for heredoc
$reg_form = <<< EOREGFORM
<P>We must ask for your name and email address to ensure that no
one votes more than once, but we do not associate your personal
information with your rating.</P>
<FORM METHOD="post" ACTION="$thisfile">
Name: <INPUT TYPE="text" SIZE=25 NAME="name"><BR><BR>
Email: <INPUT TYPE="text" SIZE=25 NAME="email">
<INPUT TYPE="hidden" NAME="stage" VALUE="register">
<BR><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Submit">
</FORM>
EOREGFORM;
$rate_form = <<< EORATEFORM
<P>My boss is:</P>
<FORM METHOD="post" ACTION="$thisfile">
<INPUT TYPE="radio" NAME="rating" VALUE=1>
Driving me to look for a new job.<BR>
<INPUT TYPE="radio" NAME="rating" VALUE=2>
Not the worst, but pretty bad.<BR>
<INPUT TYPE="radio" NAME="rating" VALUE=3>
Just so-so.<BR>
<INPUT TYPE="radio" NAME="rating" VALUE=4>
Pretty good.<BR>
<INPUT TYPE="radio" NAME="rating" VALUE=5>
A pleasure to work with.<BR><BR>
Boss’s name: <INPUT TYPE="text" SIZE=25 NAME="boss"><BR>
<INPUT TYPE="hidden" NAME="stage" VALUE="rate">
<BR><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Submit">
</FORM>
EORATEFORM;
if (!$_POST['submit']) {
// First time, just show the registration form
$message = $reg_form;
} elseif ($_POST['submit'] == 'Submit' && $_POST['stage'] ==
'register') {
// Second time, show the registration form again on error,
// rating form on successful INSERT
if (!$_POST['name'] || $_POST['name'] == "" ||
strlen($_POST['name'] > 30) || !$_POST['email'] ||
$_POST['email'] == "" || strlen($_POST['email'] > 30)) {
$message = '<P>There is a problem. Did you enter a name and
email address?</P>';
$message .= $reg_form;
} else {
// Open connection to the database
mysql_connect("localhost", "user", "password")
or die("Failure to communicate with database");
mysql_select_db("test");
// Check to see this name and email have not appeared before
$as_name = addslashes($_POST['name']);
$tr_name = trim($as_name);
$as_email = addslashes($_POST['email']);
$tr_email = trim($as_email);
$query = "SELECT sub_id FROM raters
WHERE Name = '$tr_name'
AND Email = '$tr_email'
"
or die(mysql_error());
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
error_log(mysql_error());
$message = 'Someone with this name and password has
already rated . If you think a mistake was made, please email
help@example.com.';
} else {
// Insert name and email address
$query = "INSERT INTO raters (ID, Name, Email)
VALUES(NULL, '$tr_name', '$tr_email')
";
$result = mysql_query($query);
if (mysql_affected_rows() == 1) {
$message = $rate_form;
} else {
error_log(mysql_error());
$message = '<P>Something went wrong with your signup
attempt.</P>';
$message .= $reg_form;
}
}
}
} elseif ($_POST['submit'] == 'Submit' && $_POST['stage'] ==
'rate') {
// Third time, store the rating and boss’s name
// Open connection to the database
mysql_connect("localhost", "user", "password")
or die("Failure to communicate with database");
mysql_select_db("test");
// Insert rating and boss’s name
$as_boss = addslashes($_POST['boss']);
$tr_boss = trim($as_boss);
$rating = $_POST['rating'];
$query = "INSERT INTO ratings (ID, Rating, Boss)
VALUES(NULL, '$rating', '$tr_boss')
";
$result = mysql_query($query);
if (mysql_affected_rows() == 1) {
$message = '<P>Your rating has been submitted.</P>';
} else {
error_log(mysql_error());
$message = '<P>Something went wrong with your rating
attempt. Try again.</P>';
$message .= $rate_form;
}
}
?>
<HTML>
<HEAD>
<STYLE TYPE="text/css">
<!--
BODY, P {color: black; font-family: verdana;
font-size: 10 pt}
H1 {color: black; font-family: arial; font-size: 12 pt}
-->
</STYLE>
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=10 WIDTH=100%>
<TR>
<TD BGCOLOR="#F0F8FF" ALIGN=CENTER VALIGN=TOP WIDTH=17%>
</TD>
<TD BGCOLOR="#FFFFFF" ALIGN=LEFT VALIGN=TOP WIDTH=83%>
<H1>Rate your boss anonymously</H1>
<?php echo $message; ?>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Hey guys, I new member here, just joined..The problem I have Is that I get this message after
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\rate_boss.php on line 65
So I was wondering why this script isn´t working, I did axactly how the ebook example was... (password and user on database, changed)
// First set the form strings, which will be displayed
//in various cases below
$thisfile = $_SERVER['PHP_SELF']; //Have to set this for heredoc
$reg_form = <<< EOREGFORM
<P>We must ask for your name and email address to ensure that no
one votes more than once, but we do not associate your personal
information with your rating.</P>
<FORM METHOD="post" ACTION="$thisfile">
Name: <INPUT TYPE="text" SIZE=25 NAME="name"><BR><BR>
Email: <INPUT TYPE="text" SIZE=25 NAME="email">
<INPUT TYPE="hidden" NAME="stage" VALUE="register">
<BR><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Submit">
</FORM>
EOREGFORM;
$rate_form = <<< EORATEFORM
<P>My boss is:</P>
<FORM METHOD="post" ACTION="$thisfile">
<INPUT TYPE="radio" NAME="rating" VALUE=1>
Driving me to look for a new job.<BR>
<INPUT TYPE="radio" NAME="rating" VALUE=2>
Not the worst, but pretty bad.<BR>
<INPUT TYPE="radio" NAME="rating" VALUE=3>
Just so-so.<BR>
<INPUT TYPE="radio" NAME="rating" VALUE=4>
Pretty good.<BR>
<INPUT TYPE="radio" NAME="rating" VALUE=5>
A pleasure to work with.<BR><BR>
Boss’s name: <INPUT TYPE="text" SIZE=25 NAME="boss"><BR>
<INPUT TYPE="hidden" NAME="stage" VALUE="rate">
<BR><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Submit">
</FORM>
EORATEFORM;
if (!$_POST['submit']) {
// First time, just show the registration form
$message = $reg_form;
} elseif ($_POST['submit'] == 'Submit' && $_POST['stage'] ==
'register') {
// Second time, show the registration form again on error,
// rating form on successful INSERT
if (!$_POST['name'] || $_POST['name'] == "" ||
strlen($_POST['name'] > 30) || !$_POST['email'] ||
$_POST['email'] == "" || strlen($_POST['email'] > 30)) {
$message = '<P>There is a problem. Did you enter a name and
email address?</P>';
$message .= $reg_form;
} else {
// Open connection to the database
mysql_connect("localhost", "user", "password")
or die("Failure to communicate with database");
mysql_select_db("test");
// Check to see this name and email have not appeared before
$as_name = addslashes($_POST['name']);
$tr_name = trim($as_name);
$as_email = addslashes($_POST['email']);
$tr_email = trim($as_email);
$query = "SELECT sub_id FROM raters
WHERE Name = '$tr_name'
AND Email = '$tr_email'
"
or die(mysql_error());
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
error_log(mysql_error());
$message = 'Someone with this name and password has
already rated . If you think a mistake was made, please email
help@example.com.';
} else {
// Insert name and email address
$query = "INSERT INTO raters (ID, Name, Email)
VALUES(NULL, '$tr_name', '$tr_email')
";
$result = mysql_query($query);
if (mysql_affected_rows() == 1) {
$message = $rate_form;
} else {
error_log(mysql_error());
$message = '<P>Something went wrong with your signup
attempt.</P>';
$message .= $reg_form;
}
}
}
} elseif ($_POST['submit'] == 'Submit' && $_POST['stage'] ==
'rate') {
// Third time, store the rating and boss’s name
// Open connection to the database
mysql_connect("localhost", "user", "password")
or die("Failure to communicate with database");
mysql_select_db("test");
// Insert rating and boss’s name
$as_boss = addslashes($_POST['boss']);
$tr_boss = trim($as_boss);
$rating = $_POST['rating'];
$query = "INSERT INTO ratings (ID, Rating, Boss)
VALUES(NULL, '$rating', '$tr_boss')
";
$result = mysql_query($query);
if (mysql_affected_rows() == 1) {
$message = '<P>Your rating has been submitted.</P>';
} else {
error_log(mysql_error());
$message = '<P>Something went wrong with your rating
attempt. Try again.</P>';
$message .= $rate_form;
}
}
?>
<HTML>
<HEAD>
<STYLE TYPE="text/css">
<!--
BODY, P {color: black; font-family: verdana;
font-size: 10 pt}
H1 {color: black; font-family: arial; font-size: 12 pt}
-->
</STYLE>
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=10 WIDTH=100%>
<TR>
<TD BGCOLOR="#F0F8FF" ALIGN=CENTER VALIGN=TOP WIDTH=17%>
</TD>
<TD BGCOLOR="#FFFFFF" ALIGN=LEFT VALIGN=TOP WIDTH=83%>
<H1>Rate your boss anonymously</H1>
<?php echo $message; ?>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Hey guys, I new member here, just joined..The problem I have Is that I get this message after
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\rate_boss.php on line 65
So I was wondering why this script isn´t working, I did axactly how the ebook example was... (password and user on database, changed)
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
#26
Jul 4th, 2007
put your markup in code tags please
[ code ]
[ /code ]
[ code ]
[ /code ]
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!
sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
•
•
Join Date: Mar 2007
Posts: 17
Reputation:
Rep Power: 2
Solved Threads: 0
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
#27
Jul 5th, 2007
php Syntax (Toggle Plain Text)
$query = "SELECT sub_id FROM raters WHERE Name = '$tr_name' AND Email = '$tr_email' " or die(mysql_error()); $result = mysql_query($query);
1.
your query should be
php Syntax (Toggle Plain Text)
$query = "select sub_id from raters where name = '$tr_email' and email = '$tr_email'"
your query execution statement should be
php Syntax (Toggle Plain Text)
if(mysql_query($query)){//do stuff }else{die("Could not execute");}
You can even use boolean, its really the same in the end.
But the basic mysql_query is usually
php Syntax (Toggle Plain Text)
mysql_query($query) or die();
Last edited by justinm : Jul 5th, 2007 at 12:15 am.
•
•
Join Date: Mar 2007
Posts: 17
Reputation:
Rep Power: 2
Solved Threads: 0
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
#28
Jul 5th, 2007
•
•
•
•
Try storing your query in a string. like the following.
$sql = "SELECT x FROM y";
$ret = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($ret);
theres an error in your query, which is not returning a valid result resource to your $query variable.
That is why your num_rows function is giving error.
Put your query into a string, and echo the string, so you can see if your variables are working ok.. and so on.
If you're still having bother, tell us what your query echo displays.
Cheers.
Drag.
the problem with that query is his use of a class object in the query $this->user this should be at the very least sanitised to avoid query issues.
But then again...
•
•
Join Date: Jul 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
#29
Jul 5th, 2007
okey, that helped me not to get the error thing, instead a have now empty page after inserting name and email to the imput zones...
my questions are now..
1. Have I had to do already tables and shit on the db called "test" or the script does them self?
2. How can I make this scrip work properly so that insteas of the empy page I got the boss rating thing.. I think my query isn´t working, am I right?
Thanks for those who have helped me so far...
my questions are now..
1. Have I had to do already tables and shit on the db called "test" or the script does them self?
2. How can I make this scrip work properly so that insteas of the empy page I got the boss rating thing.. I think my query isn´t working, am I right?
Thanks for those who have helped me so far...
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
#30
Jul 5th, 2007
•
•
•
•
okey, that helped me not to get the error thing, instead a have now empty page after inserting name and email to the imput zones...
my questions are now..
1. Have I had to do already tables and shit on the db called "test" or the script does them self?
2. How can I make this scrip work properly so that insteas of the empy page I got the boss rating thing.. I think my query isn´t working, am I right?
Thanks for those who have helped me so far...
Can you post your initial post please?
I can't see the initial post you're referring to.
GardCMS :: Open Source CMS :: Gardcms.org
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
Other Threads in the PHP Forum
- Previous Thread: pagination within image - IF problem
- Next Thread: How insert image into mysql database and retrieve


Linear Mode