| | |
Supplied argument is not a valid MySQL result resource
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2009
Posts: 3
Reputation:
Solved Threads: 0
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
0
#1 Apr 18th, 2009
i got this error:
my php code is this:
i searched numerous times but i can't find what's wrong with my query. plz help me
PHP Syntax (Toggle Plain Text)
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\db.php on line 13
my php code is this:
php Syntax (Toggle Plain Text)
<?php //Database Info $dbhost="localhost"; $dbuser="root"; $dbpass="something"; $dbname="somedb"; $table="users"; //Connect to Database $con=mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname, $con); $user=$_POST['user']; $pass=$_POST['pass']; $query = "SELECT * FROM $table WHERE Username=$user AND Password=$pass";//MySQL Query $result=mysql_query($query, $con);//Line 13 ERROR $numresults=mysql_num_rows($result);//Check The Number Of Results if($numresults == 1) { $handle=fopen("boxsite.html", "a+"); $contents=fread($handle, filesize("boxsite.html")); fclose($handle); echo $contents; } else { $handle=fopen("LoginFail.html", "r"); $contents=fread($handle, filesize("LoginFail.html")); fclose($handle); echo $contents; } ?>
Last edited by superyo; Apr 18th, 2009 at 2:17 pm.
•
•
Join Date: Aug 2007
Posts: 189
Reputation:
Solved Threads: 14
Enclose strings between quotes:
php Syntax (Toggle Plain Text)
$query = "SELECT * FROM $table WHERE Username='".$user."' AND Password='".$pass."'";
•
•
Join Date: Jan 2008
Posts: 79
Reputation:
Solved Threads: 9
mmm ithink there's a problem with your query.
try to echo-ing to query like this :
is it read $user and $pass variable ??
if its not read those variable you can change query syntak like this :
try to echo-ing to query like this :
PHP Syntax (Toggle Plain Text)
echo $query;
if its not read those variable you can change query syntak like this :
PHP Syntax (Toggle Plain Text)
$query = "SELECT * FROM $table WHERE Username='$user' AND Password='$pass';
•
•
Join Date: Apr 2009
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
Enclose strings between quotes:
php Syntax (Toggle Plain Text)
$query = "SELECT * FROM $table WHERE Username='".$user."' AND Password='".$pass."'";
•
•
Join Date: Aug 2007
Posts: 189
Reputation:
Solved Threads: 14
Strings, values (except numeric) in SQL must be enclosed into quotes. Quotes delimit the string content, avoiding being confused by the interpreter, due to a string can contain spaces and non-alphanumeric characters.
You started the SQL sentence with double quotes , it's important to end it with the same quotes. After the sentence I use dots to concatenate (join) variables results and add another portion of text (like the a single quote to end the string).
If that code is a login script, I suggest to use mysql_real_escape_string() on the SQL query variables to avoid a common vulnerability called MySQL injection. This function will convert the quotes that can be used on username field so the user cannot rewrite the SQL query.
More details:
http://php.net/mysql_real_escape_string
You started the SQL sentence with double quotes , it's important to end it with the same quotes. After the sentence I use dots to concatenate (join) variables results and add another portion of text (like the a single quote to end the string).
If that code is a login script, I suggest to use mysql_real_escape_string() on the SQL query variables to avoid a common vulnerability called MySQL injection. This function will convert the quotes that can be used on username field so the user cannot rewrite the SQL query.
More details:
http://php.net/mysql_real_escape_string
Last edited by martin5211; Apr 19th, 2009 at 11:07 am.
•
•
Join Date: Apr 2009
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
Strings, values (except numeric) in SQL must be enclosed into quotes. Quotes delimit the string content, avoiding being confused by the interpreter, due to a string can contain spaces and non-alphanumeric characters.
You started the SQL sentence with double quotes , it's important to end it with the same quotes. After the sentence I use dots to concatenate (join) variables results and add another portion of text (like the a single quote to end the string).
If that code is a login script, I suggest to use mysql_real_escape_string() on the SQL query variables to avoid a common vulnerability called MySQL injection. This function will convert the quotes that can be used on username field so the user cannot rewrite the SQL query.
More details:
http://php.net/mysql_real_escape_string
Oh and thanx for the tip!
![]() |
Similar Threads
- mysql_numrows(): supplied argument is not a valid MySQL result resource (PHP)
- Supplied argument is not a valid MySQL result resource (MySQL)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
- mysql_num_rows(): supplied argument is not a valid MySQL result resource in /user/690 (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
Other Threads in the PHP Forum
- Previous Thread: edit PDF with PHP
- Next Thread: Return Car Make from MySQL database & have the make hyperlinked.
| Thread Tools | Search this Thread |
ajax apache api array basics beginner binary broken cakephp checkbox class cms code codingproblem combobox cron curl database date display domain dynamic echo email error file files folder form format forms function functions google href htaccess html image include insert interactive ip java javascript joomla js limit link load login mail malfunctioning menu mlm mobile multiple mysql nodes oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion reference remote return script search server sessions sms source space sql syntax system table tutorial unset up-to-date update upload url validation validator variable video web webapplications websitecontactform youtube





