DeathStar Posted April 4, 2007 Share Posted April 4, 2007 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 More sharing options...
almightyegg Posted April 4, 2007 Share Posted April 4, 2007 Replace this: $uq=mysql_query("SELECT pid FROM players WHERE name='$name' AND `passwd`=$password"); With this: $uq = mysql_query("SELECT pid FROM players WHERE name='$name' AND passwd='$password'"); try that Link to comment https://forums.phpfreaks.com/topic/45589-warning-mysql_num_rows/#findComment-221370 Share on other sites More sharing options...
DeathStar Posted April 4, 2007 Author Share Posted April 4, 2007 nope Link to comment https://forums.phpfreaks.com/topic/45589-warning-mysql_num_rows/#findComment-221374 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 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 Link to comment https://forums.phpfreaks.com/topic/45589-warning-mysql_num_rows/#findComment-221377 Share on other sites More sharing options...
DeathStar Posted April 4, 2007 Author Share Posted April 4, 2007 Problem with the query SELECT pid FROM players WHERE name=test AND passwd=test Query was empty it returned that.. query should not be empty. made connecting, now calling it. Link to comment https://forums.phpfreaks.com/topic/45589-warning-mysql_num_rows/#findComment-221387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.