| | |
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2007
Posts: 1
Reputation:
Solved Threads: 0
I have been looking at this code for some time and just can not figure anything wron with it.
My Error Message is: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hsphere/local/home/gwthorn/htpsinc-web.com/York_County/login.php on line 13
I commeted 13
My Error Message is: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hsphere/local/home/gwthorn/htpsinc-web.com/York_County/login.php on line 13
I commeted 13
php Syntax (Toggle Plain Text)
<?php session_start(); //The fields are censored but the database does connect. mysql_connect("-censored-","-censored-","-censored"); mysql_select_db("-censored-"); if(isset($_POST['login'])) { $username = htmlspecialchars($_POST['username'], ENT_QUOTES); $password = htmlspecialchars($_POST['password'], ENT_QUOTES); $password = md5($password); $sql = mysql_query("SELECT * FROM user_system WHERE username='$username' AND password='$password'"); if(mysql_num_rows($sql)>0) { //!!!!!!!!!!!!!!!!!!!!!!!!Line 13 $_SESSION['auth'] = true; setcookie("avxsystem_user",$username,time()+30*30*30*30*365); setcookie("avxsystem_pass",$password,time()+30*30*30*30*365); echo "<p>Login Successful</p>"; } else { echo "<p>Sorry, you are unable to login because you have got your username/password combination wrong. Please check spelling & try again."; } } else { echo $message; } ?>
Last edited by stymiee; May 7th, 2007 at 11:00 am. Reason: used php [code]
That means your query failed. Echo it out and look for an error or use mysql_error() to see what the error is.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
i'm not so sure though, but i guess, there's something wrong in your query... with regards to the proper usage of single quotation marks... single quotation marks will be taken literally so for example '$username' is the same as $username (literally) while "$username" will be taken by it's value so for example if $username=50; echo "$username"; ---> the output is 50.
hmmm... i'm not so sure bout this though... i'm still a student...
hmmm... i'm not so sure bout this though... i'm still a student...
The quotes are ok.
I think your problem comes from that piece of code, because if you give an echo to before entering it in the mysql query you will probably see your username string contains at least one # charcater (the password is hashed anyway so doesn't have this problem).
Anyway, if your username string contains a # character, in mysql everything after that char is considered a comment so your sql statement is broken in that point and that's why you get this error.
I suggest you test it first with some simple, clean strings (user: abcd, pass: xyzw) and without and see if it works and after that go to more complicated stuff.
I think your problem comes from that
PHP Syntax (Toggle Plain Text)
htmlspecialchars
htmlspecialchars($_POST['username'], ENT_QUOTES);
Anyway, if your username string contains a # character, in mysql everything after that char is considered a comment so your sql statement is broken in that point and that's why you get this error.
I suggest you test it first with some simple, clean strings (user: abcd, pass: xyzw) and without
htmlspecialchars johy_d is right. Your problem could well lie within the htmlspecialchars() function.
Only way to identify this is.
Instead of putting the query directly into mysql_query().
Do.
NOTE: After observing your query, you'll need to remote the exit; or the "echo $query; exit;" So that execution can continue onto the mysql_query() function.
Identify what is working first, before trying to figure out what isnt working.
Any questions just ask.
Only way to identify this is.
Instead of putting the query directly into mysql_query().
Do.
PHP Syntax (Toggle Plain Text)
$query = "SELECT * FROM table"; /* This will output your query then exit the script */. echo $query; exit; /* run query with mysql error functionallity */ $ret = mysql_query($query) or die(mysql_error());
NOTE: After observing your query, you'll need to remote the exit; or the "echo $query; exit;" So that execution can continue onto the mysql_query() function.
Identify what is working first, before trying to figure out what isnt working.
Any questions just ask.
GardCMS :: Open Source CMS :: Gardcms.org
![]() |
Similar Threads
- Warning: mysql_num_rows(): 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_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
Other Threads in the PHP Forum
- Previous Thread: Ip Reading
- Next Thread: XML and str_replace !
| Thread Tools | Search this Thread |
.htaccess access alexa apache api array beginner binary broken cakephp checkbox class cms code convert cron curl database date directory display dropdown dynamic echo email encode error fairness file files folder form forms function functions google hack href htaccess html htmlspecialchars image include indentedsubcategory insert ip javascript joomla limit link login mail mail() menu methods mlm multiple multipletables mysql network newsletters object oop passwords paypal pdf php problem provider query radio random recursion redirect remote script search secure securephp server sessions simple sms source space sql syntax system table tutorial update upload url user validator variable video voteup web youtube






