Jump to content

Problem with Login page


ajitvaghela

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/273277-problem-with-login-page/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.