thelostdutchmann Posted June 16, 2013 Share Posted June 16, 2013 hey i was typing a smale login code but i keep geting this waring Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/u400486/domains/u400486.gluweb.nl/public_html/lekkerpittig/register.php on line 17 and it won't save on my table but i tink thats becouse of the waring can someone help out <?php include('config.php'); if($_SERVER['REQUEST_METHOD'] == 'POST'){ $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string(md5($_POST['password'])); if(empty($username)){ echo("you have to fill in an username!"); } else{ if(empty($password)){ echo("you have to fill in a password!"); } else{ $query = mysql_query("SELECT * FROM users WHERE username ='$username'"); $rows = mysql_num_rows($query); if($rows > 0){ die ("Username taken!"); }else{ $user_input = mysql_query("INSERT INTO users(username , password) VALUES('$username' , '$password')"); echo("succesfully registered!"); } } } } ?> <html> <head> <title>register</title> </head> <body> <form action="register.php" method="post"/> username: <input type="text" name="username"/> <br /> password: <input type="password" name="password"/> <br /> <input type="submit" value="resister!" /> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/279223-warning-mysql_num_rows-expects-parameter-1-to-be-resource/ Share on other sites More sharing options...
trq Posted June 16, 2013 Share Posted June 16, 2013 Your query is failing for whatever reason and you are doing absolutely no error handling to accommodate it. Check that $query (also a nonsensical name for this variable) is what mysql_num_rows is expecting before blindly passing it in. You can find out why your query os failing by looking at the output from mysql_error(). Link to comment https://forums.phpfreaks.com/topic/279223-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1436217 Share on other sites More sharing options...
thelostdutchmann Posted June 16, 2013 Author Share Posted June 16, 2013 solved it the mysq_error told me that no database was selected my classmate gave me the wrong database name Link to comment https://forums.phpfreaks.com/topic/279223-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1436219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.