Reputation:
when I run this script I am trying to echo the session variable($email)by redirecting the session via a header to location:index.php, but it just echos the session value (the number 1) not the email address and I can't figure out why. Any Ideas? Thanks.
<?php
session_start();
if (isset($_POST['email'], $_POST['password'])) {
$email = $_POST['email'];
$password = $_POST['password'];
if ($email && $password) {
$connect = mysql_connect("localhost", "root", "") or die("Could not connect");
mysql_select_db("test") or die("could not find database");
$query = mysql_query("SELECT * FROM users WHERE email='$email'&&
password= md5('$password')");
$numrows = mysql_num_rows($query);
if ($numrows != 0) {
$_SESSION["email"] = $email;
session_write_close();
header("location:index.php");
Die();
}
else
echo ("not a user");
}
else
echo("enter both fields");
}
?>
<html>
<form action='edit1.php' method='POST'>
<table align='right' bgcolor='blue'>
<tr>
<td>Email
</td>
<td>Password
</td>
</tr>
<tr>
<td><input name='email' type='text'>
</td>
<td><input name='password' type='password'><td>
<input type='submit' value='login'>
</td>
</tr>
</table>
</form>
</html>
//index.php file
<?php
session_start(); {
echo $_SESSION['email'] or die('fail'); {
}
}
?>
Upvotes: 1
Views: 411
Reputation: 10206
Remove the or die('fail') and it will work fine.
The function echo returns void rendering 'or die()' useless
Upvotes: 0
Reputation: 11122
As I said in the comment, the or die
will not work. Remove it.
Upvotes: 3