User Name Password Register
DaniWeb IT Discussion Community
All
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,633 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,793 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: 100368 | Replies: 43
Reply
Join Date: Apr 2007
Posts: 136
Reputation: dr4g is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
dr4g's Avatar
dr4g dr4g is offline Offline
Junior Poster

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

  #21  
May 10th, 2007
Well at least w_3rabi has fixed your initial mysql_num_rows() error !.

It's onto a new error now.
Last edited by dr4g : May 10th, 2007 at 10:25 am.
GardCMS :: Open Source CMS :: Gardcms.org
Reply With Quote  
Join Date: May 2007
Posts: 3
Reputation: acaradic@hotmai is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
acaradic@hotmai acaradic@hotmai is offline Offline
Newbie Poster

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

  #22  
May 10th, 2007
Yup, i hope somebody will come up with something cose it's giving me a headache!
Tryied everythin but with no result.

Thank you all!
Reply With Quote  
Join Date: Jul 2007
Posts: 1
Reputation: theflyingtom is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
theflyingtom theflyingtom is offline Offline
Newbie Poster

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)
 
$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.
Reply With Quote  
Join Date: Apr 2007
Posts: 136
Reputation: dr4g is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
dr4g's Avatar
dr4g dr4g is offline Offline
Junior Poster

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

  #24  
Jul 2nd, 2007
Originally Posted by theflyingtom View Post
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
Reply With Quote  
Join Date: Jul 2007
Posts: 3
Reputation: Chulo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Chulo Chulo is offline Offline
Newbie Poster

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)
Reply With Quote  
Join Date: Apr 2004
Location: Tracy
Posts: 743
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 32
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

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 ]
!!!!! 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!
Reply With Quote  
Join Date: Mar 2007
Posts: 17
Reputation: justinm is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
justinm justinm is offline Offline
Newbie Poster

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

  #27  
Jul 5th, 2007
  1. $query = "SELECT sub_id FROM raters
  2. WHERE Name = '$tr_name'
  3. AND Email = '$tr_email'
  4. "
  5. or die(mysql_error());
  6. $result = mysql_query($query);

1.
your query should be
  1. $query = "select sub_id from raters where name = '$tr_email' and email = '$tr_email'"
2.
your query execution statement should be
  1. if(mysql_query($query)){//do stuff
  2. }else{die("Could not execute");}

You can even use boolean, its really the same in the end.
But the basic mysql_query is usually
  1. mysql_query($query) or die();
Last edited by justinm : Jul 5th, 2007 at 12:15 am.
Reply With Quote  
Join Date: Mar 2007
Posts: 17
Reputation: justinm is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
justinm justinm is offline Offline
Newbie Poster

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

  #28  
Jul 5th, 2007
Originally Posted by dr4g View Post
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...
Reply With Quote  
Join Date: Jul 2007
Posts: 3
Reputation: Chulo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Chulo Chulo is offline Offline
Newbie Poster

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...
Reply With Quote  
Join Date: Apr 2007
Posts: 136
Reputation: dr4g is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
dr4g's Avatar
dr4g dr4g is offline Offline
Junior Poster

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

  #30  
Jul 5th, 2007
Originally Posted by Chulo View Post
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 1:01 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC