Current location: Hot Scripts Forums » Programming Languages » PHP » Warning: mysql_num_rows(): supplied...


Warning: mysql_num_rows(): supplied...

Reply
  #1 (permalink)  
Old 09-11-09, 12:45 PM
Skiller89 Skiller89 is offline
New Member
 
Join Date: Sep 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Warning: mysql_num_rows(): supplied...

Hi!
I try to get work this script:
PHP Code:

<?php

session_start
();
require 
"database.php";

$title=$_POST['message_title'];
$to=$_POST['message_to'];
$content=$_POST['message_content'];
$from=$_POST['message_from'];
$time=$_POST['message_date'];

$ck_reciever "SELECT username FROM user WHERE username = '".$to."'";

        
        if( 
mysql_num_rowsmysql_query$ck_reciever ) ) == ){
die(
"The user you are trying to contact don't excist. Please go back and try again.<br>
<form name=\"back\" action=\"new_message.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
"
);
}
elseif(
strlen($content) < 1){
die(
"Your can't send an empty message!<br>
<form name=\"back\" action=\"new_message.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
"
);
}
elseif(
strlen($title) < 1){
die(
"You must have a Title!<br>
<form name=\"back\" action=\"new_message.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
"
);
}else{
mysql_query("INSERT INTO messages (from_user, to_user, message_title, message_contents, message_date) VALUES ('$from','$to','$title','$content','$time')") OR die("Could not send the message: <br>".mysql_error()); 
echo 
"The Message Was Successfully Sent!";
?>
<form name="back" action="inbox.php"
method="post">
<input type="submit" value="Back to The Inbox">
</form>
<?php
}
?>
And if i send message then its says
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/"user"/public_html/private/messageck.php on line 14
I hope someone can help me to get work this
Reply With Quote
  #2 (permalink)  
Old 09-11-09, 01:35 PM
carters-site's Avatar
carters-site carters-site is offline
Wannabe Coder
 
Join Date: Sep 2009
Location: Moline, IL
Posts: 100
Thanks: 2
Thanked 1 Time in 1 Post
This is not returning a result object like you are assuming it should.
PHP Code:

]

mysql_query$ck_reciever 
I assume the mysql connection is happening in database.php.

You should really be checking for a mysql error after a any query you do. It's a good practice to get into. I would check to see what mysql_query is returning here is some code right from php.net that shows how to check for a query problem

PHP Code:

$result mysql_query('SELECT * WHERE 1=1');

if (!
$result) {
    die(
'Invalid query: ' mysql_error());

I also want to point out a security hole open for SQL Injection using your method of building the query. You will want to escape that before you just plug username in since you are just plugging that value in from a POST variable.

reference this method built into PHP or switch to use a PEAR Database package.
PHP: mysql_real_escape_string - Manual
Reply With Quote
  #3 (permalink)  
Old 09-11-09, 04:06 PM
Skiller89 Skiller89 is offline
New Member
 
Join Date: Sep 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Still nothing :S
Maybe someone know some another private message script?
Reply With Quote
  #4 (permalink)  
Old 09-11-09, 07:02 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
PHP Code:

<?php
session_start
();
require 
"database.php";

$title=$_POST['message_title'];
$to=$_POST['message_to'];
$content=$_POST['message_content'];
$from=$_POST['message_from'];
$time=$_POST['message_date'];

$ck_reciever "SELECT username FROM user WHERE username = '".$to."'";
mysql_query($ck_reciever) or die(mysql_error());
        
        if( 
mysql_affected_rows() == ){
die(
"The user you are trying to contact don't excist. Please go back and try again.<br>
<form name=\"back\" action=\"new_message.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
"
);
}
elseif(
strlen($content) < 1){
die(
"Your can't send an empty message!<br>
<form name=\"back\" action=\"new_message.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
"
);
}
elseif(
strlen($title) < 1){
die(
"You must have a Title!<br>
<form name=\"back\" action=\"new_message.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
"
);
}else{
mysql_query("INSERT INTO messages (from_user, to_user, message_title, message_contents, message_date) VALUES ('$from','$to','$title','$content','$time')") OR die("Could not send the message: <br>".mysql_error()); 
echo 
"The Message Was Successfully Sent!";
?>
<form name="back" action="inbox.php"
method="post">
<input type="submit" value="Back to The Inbox">
</form>
<?php
}
?>
Try that, and see what it says. I even left the spelling errors in there for you.
Reply With Quote
  #5 (permalink)  
Old 09-12-09, 03:22 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
SELECT queries don't return affected rows.

Try:
PHP Code:

$result mysql_query($ck_reciever) or die(mysql_error());
        
if (
mysql_fetch_assoc($result)) { 

And escape your input properly if you want to avoid SQL injections.
PHP: mysql_real_escape_string - Manual
Reply With Quote
  #6 (permalink)  
Old 09-12-09, 03:32 AM
Skiller89 Skiller89 is offline
New Member
 
Join Date: Sep 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Jcbones, this working now
Reply With Quote
  #7 (permalink)  
Old 09-12-09, 01:26 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Quote:
Originally Posted by Nico View Post
SELECT queries don't return affected rows.

Try:
PHP Code:

$result mysql_query($ck_reciever) or die(mysql_error());

        
if (
mysql_fetch_assoc($result)) { 

And escape your input properly if you want to avoid SQL injections.
PHP: mysql_real_escape_string - Manual
Well, learn something new everyday. You are right, it shouldn't (according to the manual), but it does on my test server, and on my public server.
Reply With Quote
Reply

Bookmarks


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result cpmross PHP 6 07-13-07 05:58 PM
Firefox and align problems gigafare CSS 12 01-07-07 11:22 AM
help with error messages.. please APuppyDog PHP 2 10-05-06 11:09 PM
Warning: feof(): supplied argument is not a valid stream resource in danielta PHP 1 07-14-06 09:19 PM
NEED HELP - Warning: mysql_fetch_array(): supplied argument is not a valid MySQL r ArgonX PHP 4 08-19-04 01:59 PM


All times are GMT -5. The time now is 07:59 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.