tammana Posted February 12, 2012 Share Posted February 12, 2012 Hi I am very new to php. i am just learning php. I am trying to go to profile page from login page so i created a page process to fetch username and password. but it is giving me an error ( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\project\process.php on line 12 i don't understand what does this error mean? here is my code: <?php mysql_connect("localhost", "root", ""); mysql_select_db("project"); $result = mysql_query("SELECT id From users where username='".$_POST['username']."'" and "password='".$_POST['password']."'"); $row = mysql_fetch_array($result); $_SESSION['userid']=$row['id']; ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 12, 2012 Share Posted February 12, 2012 Your query is failing and returning a boolean value of FALSE to mysql_fetch_array(). Edit your code so the query string is in a variable, then you can echo both the query string and any errors returned from MySQL. $query = "SELECT id FROM users WHERE username = '{$_POST['username']}' AND password = '{$_POST['password']}"; $result = mysql_query($query) or die( "<br>Query string: $query<br>Produced error: " . mysql_error() ); $row = mysql_fetch_array($result); Quote Link to comment Share on other sites More sharing options...
El Chupacodra Posted February 16, 2012 Share Posted February 16, 2012 $result = mysql_query("SELECT id From users where username='".$_POST['username']."'" and "password='".$_POST['password']."'"); If you look at the quotation marks you seem to cut the query off at this point: ...username']."'" and... It should work if you write it like $result = mysql_query("SELECT id From users where username='".$_POST['username']."' AND password='".$_POST['password']."'"); If you plan to keep coding it's better to do like Pikachu said, assign the values from the form to variables and put the query in another variable. Then you can echo all variables and see if they look right AND echo the query itself. Also, after the query you can put a die clause with the sql error so you get a message saying what went wrong. So like this: $username = $_POST['username']; $password = $_POST['password']; $query = "SELECT id From users where username='$username' AND password='$password'"; $result = mysql_query($query) or die("Query failed".mysql_error()); If I messed that up it will tell you why. 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.