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? Link to comment https://forums.phpfreaks.com/topic/127065-solved-mysql-error/ 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? Link to comment https://forums.phpfreaks.com/topic/127065-solved-mysql-error/#findComment-657292 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. Link to comment https://forums.phpfreaks.com/topic/127065-solved-mysql-error/#findComment-657294 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. Link to comment https://forums.phpfreaks.com/topic/127065-solved-mysql-error/#findComment-657295 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(); ?? Link to comment https://forums.phpfreaks.com/topic/127065-solved-mysql-error/#findComment-657300 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 Link to comment https://forums.phpfreaks.com/topic/127065-solved-mysql-error/#findComment-657303 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? Link to comment https://forums.phpfreaks.com/topic/127065-solved-mysql-error/#findComment-657315 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. Link to comment https://forums.phpfreaks.com/topic/127065-solved-mysql-error/#findComment-657316 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] Link to comment https://forums.phpfreaks.com/topic/127065-solved-mysql-error/#findComment-657317 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? Link to comment https://forums.phpfreaks.com/topic/127065-solved-mysql-error/#findComment-657321 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' Link to comment https://forums.phpfreaks.com/topic/127065-solved-mysql-error/#findComment-657329 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. Link to comment https://forums.phpfreaks.com/topic/127065-solved-mysql-error/#findComment-657350 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.