ngreenwood6 Posted October 4, 2008 Share Posted October 4, 2008 I have the following page: <?php //include the variables include("includes/variables.php"); //define the variable from the form $username = strtolower($_POST['username']); //connect to the database $connect = mysql_connect($host,$user,$pass) or die("could not connect"); //select the database $select_db = mysql_select_db($db); //query for the database $query = "SELECT * FROM $table WHERE username = '$username'"; //get the results $results = mysql_query($query); //number the rows $num_rows = mysql_num_rows($results); if ($num_rows == 1) { //put it into an array $row = mysql_fetch_array($results); } //give the username a variable $row_username = $row['username']; //if the username is not in the database if($num_rows < 1) { echo "That username is not in the database!"; } ?> Whenever I submit the form I get this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\check_user.php on line 21 Any ideas why? Quote Link to comment Share on other sites More sharing options...
Andy-H Posted October 5, 2008 Share Posted October 5, 2008 Is the $table variable defined in variables.php? And is it a valid table name? Quote Link to comment Share on other sites More sharing options...
Chicken Little Posted October 5, 2008 Share Posted October 5, 2008 Try changing your query from $table to table. Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted October 5, 2008 Author Share Posted October 5, 2008 yeah it is. It looks like: $table = "table"; I also tried just putting the table name in there. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted October 5, 2008 Share Posted October 5, 2008 does variables.php initialise a session? session_start(); ?? Quote Link to comment Share on other sites More sharing options...
Andy-H Posted October 5, 2008 Share Posted October 5, 2008 nvm just saw $username is POST data Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted October 5, 2008 Author Share Posted October 5, 2008 does anyone know what the actual error means? Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 5, 2008 Share Posted October 5, 2008 Change: $results = mysql_query($query); to: $results = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query;) That should explain what's going on/going wrong. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted October 5, 2008 Share Posted October 5, 2008 [quote author=AndyB link=topic=219574.msg1006417#msg1006417 date=1223166510] Change: [code]$results = mysql_query($query); to: $results = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); That should explain what's going on/going wrong.[/code] Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted October 5, 2008 Author Share Posted October 5, 2008 It is giving me this error now: Error: No database selected with query SELECT * FROM users WHERE username='test' I even tried changing the: $select_db = mysql_select_db($db); to: mysql_select_db("database"); Any ideas? Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 5, 2008 Share Posted October 5, 2008 You need to use the complete/correct name you gave your database. I doubt it's named 'database' Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted October 5, 2008 Author Share Posted October 5, 2008 I am not that dumb I used the database name. I was just using database for the example so you would know that i put the database name in there. Anyways i got it working. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.