Jump to content

login script not getting id


silverglade

Recommended Posts

Hi, I am trying to make a login script that uses the user's id from the database, and tries to match it up with the user and password sent by the login form. My checklogin.php page, just jumps back to the index.php page for some reason. I don't know why. I get the following errors, any help greatly appreciated. thank you.

 

Notice: Undefined index: myusername in /hermes/bosweb/web173/b1739/public_htmlchecklogin.php on line 19

 

Notice: Undefined index: mypassword in /hermes/bosweb/web173/b1739/public_html/checklogin.php on line 20

Wrong Username or Password

 

Here is my code to check the id. I can't figure out what is wrong.

 

<?php 

ini_set ("display_errors", "1");
error_reporting(E_ALL);
$host		= "";
$database 	= "";
$username 	= "";
$password 	= ""; 
$tbl_name   = "users";
$conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error());

if($conn)
{
mysql_select_db($database);
} else {
	echo "failed to select database";
}	
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT id FROM $tbl_name WHERE username='$myusername' and password= SHA1('$mypassword')";
$result=mysql_query($sql);
$query_data = mysql_fetch_row($result);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result)
;
// If result matched id, table row must be 1 row
if($count==1){
session_start();

     $_SESSION['userid']=$query_data[0];


header("location:login_success.php");
}

else {
echo "Wrong Username or Password";
}

?>

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.