ajitvaghela Posted January 17, 2013 Share Posted January 17, 2013 Hi, Below is my PHP code and there is error says "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in H:\wamp\www\My_Project\login_action.php on line 29 which is at $sel_user=mysql_query("select * from registration where username='$id'"); <?php session_start(); $host="localhost"; $user="root"; $pass=""; $db_name="myproject_db"; $link=mysql_connect($host,$user,$pass); if(!$link) { echo "Database not connected"; die ('Could not connect to database' .mysql_error()); } $id = $_POST['login_uname']; $pwd = $_POST['login_pwd']; $enc_ps = md5($pwd); $sel_user=mysql_query("select * from registration where username='$id'"); if(!$sel_user) echo "No user found"; while($row=mysql_fetch_array($sel_user)) { if($row['username']==$id && $row['password']==$enc_ps) { $_SESSION['logged_user']= $id1; //save user in session variable header('Location:index.php'); } else{ echo "Invalid Username or Password"; break; } } ?> Please help me on this... Regards, AJ Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 17, 2013 Share Posted January 17, 2013 (edited) Your query is failing, please see this post for information on how to debug it. Edited January 17, 2013 by Christian F. Quote Link to comment Share on other sites More sharing options...
ajitvaghela Posted January 18, 2013 Author Share Posted January 18, 2013 Hi Christian, Thanks a lot for your help, I debug my code by adding following code: if($sel_user === FALSE) { die(mysql_error()); } And finally I figured out the problem, It was minor mistake I actually forgot to select the database so just selected database "mysql_select_db($db_name,$link);" and it works now.. Thanks again Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 18, 2013 Share Posted January 18, 2013 You're welcome, glad I could be of help. 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.