10 Replies - 1651 Views - Last Post: 29 April 2011 - 04:25 AM Rate Topic: -----

#1 MARAM AL  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 09-April 11

small problem in php log in

Posted 28 April 2011 - 01:17 PM

hey this is my cod login

login.php

<?php

session_start();

$KSUEmail = $_POST['KSUEmail'];
$Password = $_POST ['Password'];

if ($KSUEmail&&$Password)
{
$connect = mysql_connect("localhost","root","") or die("Could not connect!");
mysql_select_db("website") or die("Could not find db");

$query=mysql_query("select * from member where KSUEmail = '$KSUEmail'");

$numrows= mysql_num_rows($query);

if($numrows!=0)
{
while ($row =mysql_fetch_assoc($query))
{
$dbKSUEmail=$row['KSUEmail'];
$dbPassword=$row ['Password'];
$dbmember=$row['memberName'];

if ($username==$dbusername && $password==$dbpassword)
{
echo " welcome <a href='Home.php'>click here </a>";
$_SESSION['memberName']=$dbmember;
}
else
echo"Incorrect password, please try again";
}
}
else 
die ("That username does not exist in our database");

}
else
die("please enter email and password");



?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Home</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
	<div id="header">
		<div id="register">
	<p><input type="submit" value="Register" /></p>
			</div>

		<div id="logo">
			<img src="images/1 logo.jpg" width="160" height="80" alt="" /></p>
			
		
		</div>
	</div>
	<!-- end #header -->
	<div id="page">
		<div id="page-bgtop">
			<div id="page-bgbtm">
				<div id="content">
					<div class="post">
						<h2 class="title"><a href="#">Welcome to Academic Events Searching System </a></h2>
	
						<div class="entry">
							<P> decropation</P>
						</div>
					</div>

					<div style="clear: both;">&nbsp;</div>
				</div>
				<!-- end #content -->
				<div id="sidebar">
				<br>
				<br>
				<br>
				<form method="POST" action="login.php">

  E-mail:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="KSUEmail" maxlength="30">
  <br /><br />
  Password: <input type="password" name="Password" maxlength="30"><br /><br />
  <div align="center">
  <a href="url">Forget Password</a> <br /> 
	 <p><input type="submit" name="submit" value="Log in"></p>
  </div>
</form>





and the erro

Notice: Undefined index: KSUEmail in C:\xampp\htdocs\login.php on line 5

Notice: Undefined index: Password in C:\xampp\htdocs\login.php on line 6
please enter email and password

and my database name is
website
that contine
table member
have
memberID
memberName
KSUEmail
SEmail
Major
EduDeg
Password

and i will use thse cod en every page

<?php
session_start();
echo " welcome "$_SESSION['memberName']"!";
?>


and thse is code for logout

<?php

session_start();
session_destroy();
echo " you have been logout";
?>

This post has been edited by Dormilich: 28 April 2011 - 11:29 PM


Is This A Good Question/Topic? 0
  • +

Replies To: small problem in php log in

#2 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: small problem in php log in

Posted 28 April 2011 - 02:16 PM

Your page is trying to deal with the $_POST array before the form has even been submitted.

you can fix it by changing just a couple of lines

$KSUEmail = isset($_POST['KSUEmail']) ? $_POST['KSUEmail'] : false;
$Password = isset($_POST ['Password']) ? $_POST ['Password'] : false;



should set your variables to false if they are not set.

or you can use isset() in your if statement to check if the variables are set or not as well.

edit:

you can omit this portion of code to keep from seeing the "please enter ..." message pop up and killing the script every time as well

else
die("please enter email and password");



or wrap your entire processing code in a if (isset($_POST)) statement

This post has been edited by RPGonzo: 28 April 2011 - 02:23 PM

Was This Post Helpful? 0
  • +
  • -

#3 MARAM AL  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 09-April 11

Re: small problem in php log in

Posted 28 April 2011 - 02:22 PM

it display blank page that writen inside it
please enter email and password
Was This Post Helpful? 0
  • +
  • -

#4 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: small problem in php log in

Posted 28 April 2011 - 02:23 PM

Its because of the last die statement ... the PHP is killing the script therefore not showing your login form.

either omit that bit of code or wrap everything in a if statement.
Was This Post Helpful? 0
  • +
  • -

#5 MARAM AL  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 09-April 11

Re: small problem in php log in

Posted 28 April 2011 - 02:27 PM

yes i do what u say
then i try the cod
with correct password and email
and it display
That username does not exist in our database
Was This Post Helpful? 0
  • +
  • -

#6 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: small problem in php log in

Posted 28 April 2011 - 02:41 PM

Does it exist in the database?

You should really start by debugging your script as you go,not saying your SQL is your issue but one spot to start

$query=mysql_query("select * from member where KSUEmail = '$KSUEmail'") or die(mysql_error());



debugging can be your best friend, you just need to utilize it.
Was This Post Helpful? 0
  • +
  • -

#7 MARAM AL  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 09-April 11

Re: small problem in php log in

Posted 28 April 2011 - 02:47 PM

the same thing is hppeen
That username does not exist in our database

i think the erro in the name of varible maybe
Was This Post Helpful? 0
  • +
  • -

#8 MARAM AL  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 09-April 11

Re: small problem in php log in

Posted 28 April 2011 - 02:56 PM

i change cod

<?php
session_start();

$KSUEmail = (isset($_POST['KSUEmail'])) ? $_POST['KSUEmail'] : null;
$Password = (isset($_POST ['Password'])) ? $_POST['Password'] : null;

if ($KSUEmail && $Password) {
$connect = mysql_connect("localhost", "root", "") or die("Could not connect!");
mysql_select_db("website") or die("Could not find db");

$query = mysql_query("select * from member where KSUEmail = '$KSUEmail'");

$numrows = mysql_num_rows($query);

if ($numrows != 0) {
while ($row = mysql_fetch_assoc($query)) {
$dbKSUEmail = $row['KSUEmail'];
$dbPassword = $row ['Password'];
$dbmember = $row['memberName'];

if ($username == $dbusername && $password == $dbpassword) 
{
echo " welcome <a href='Home.php'>click here </a>";
$_SESSION['memberName'] = $dbmember;
}
else
echo"Incorrect password, please try again";
}
}
else
die("That username does not exist in our database");
}
else {
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Home</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="register">
<p><input type="submit" value="Register" /></p>
</div>

<div id="logo">
<img src="images/1 logo.jpg" width="160" height="80" alt="" /></p>


</div>
</div>
<!-- end #header -->
<div id="page">
<div id="page-bgtop">
<div id="page-bgbtm">
<div id="content">
<div class="post">
<h2 class="title"><a href="#">Welcome to Academic Events Searching System </a></h2>

<div class="entry">
<P> decropation</P>
</div>
</div>

<div style="clear: both;"> </div>
</div>
<!-- end #content -->
<div id="sidebar">
<br>
<br>
<br>
<form method="POST" action="<?php echo $_SERVER['SCRIPT_NAME'] ?>">

E-mail: <input type="text" name="KSUEmail" maxlength="30">



Password: <input type="password" name="Password" maxlength="30">


<div align="center">
<a href="url">Forget Password</a> 

<p><input type="submit" name="submit" value="Log in"></p>
</div>
</form>
<?php
}
?>






then it display
Notice: Undefined variable: dbusername in C:\xampp\htdocs\login.php on line 21

Notice: Undefined variable: username in C:\xampp\htdocs\login.php on line 21

Notice: Undefined variable: dbpassword in C:\xampp\htdocs\login.php on line 21

Notice: Undefined variable: password in C:\xampp\htdocs\login.php on line 21
welcome click here
Was This Post Helpful? 0
  • +
  • -

#9 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: small problem in php log in

Posted 28 April 2011 - 02:59 PM

echo your variables to double check the values, also watch for spaces as well.

data validation and security needs to be your number on with a login form, yours is not.

if your unsure how to do these things tutorials will help GREATLY!

http://www.dreaminco...-point-of-view/
Was This Post Helpful? 0
  • +
  • -

#10 MARAM AL  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 09-April 11

Re: small problem in php log in

Posted 28 April 2011 - 03:06 PM

thanks i correct the erro
but i have question

the message like
Incorrect password, please try again
it display in another page
how can it display in the same page
Was This Post Helpful? 0
  • +
  • -

#11 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: small problem in php log in

Posted 29 April 2011 - 04:25 AM

If you don't mind showing us at least one row in your database. A screen shot will do just fine. Reason why is I'm not sure whether you applied the hash or not to your passwords like i told you to in your last thread.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1