Jump to content

Warning: mysql_num_rows():...


DeathStar

Recommended Posts

Hi there i dont knwo why but i keep getting this error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/*****/public_html/login.php on line 15

 

its strange i always get this error wherever i make an login!

 

code :

<?php
session_start();
mysql_connect ('localhost','deadlc','hexor') or die(mysql_error());
mysql_select_db('deadlc_db1') or die ("could not open db".mysql_error());
print "<div align='center'>";
if ($_POST){
$name = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$ip = ($_SERVER['REMOTE_ADDR']);
$hostname = ($_SERVER['REMOTE_HOST']);
$id = mysql_query("SELECT name FROM players WHERE name=$name");
$uq=mysql_query("SELECT pid FROM players WHERE name='$name' AND `passwd`=$password");
if ($name == "" || $password == ""){
print "<body bgcolor=black><center><table border=4 bordercolor=red><tr><td><font color=red><center>You did not enter a Username or Password.</font></td></tr></table><br />";}
elseif (mysql_num_rows($uq)==0){
print "<body bgcolor=black><center><table border=4 bordercolor=red><tr><td><font color=red><center>Incorrect Username or Password.</font></td></tr></table><br />";}
else{ 
$hour = time() + 3600;
setcookie(id, $id, $hour);
echo "You will be redirected in 5 seconds.<br />If not click <a href=index.php>here</a><br />
<meta http-equiv='refresh' content='5;url=index.php' />";
}
}

?>

form is here....

Link to comment
https://forums.phpfreaks.com/topic/45589-warning-mysql_num_rows/
Share on other sites

When you get that error it means that the query did not work, change this

<?php
$uq=mysql_query("SELECT pid FROM players WHERE name='$name' AND `passwd`=$password");
?>

to

<?php
$qtmp = "SELECT pid FROM players WHERE name='$name' AND `passwd`=$password"
$uq=mysql_query($q) or die("Problem with the query <pre>$qtmp</pre><br>" . mysql_error());
?>

 

And see what is printed.

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.