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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.