I solve The problem Thank you ALL I move all php code in the first line of page(above head section ) except the case when user inter wrong email i leave it in the body ^_^
I have this log in code which checks if a user is already member or not.
<?php
$con=mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("mydb")or die("error in selecting db");
$email = $_POST['email'];
$password = $_POST['password'];
if( $email && $password)
{
$query = "select * from users where email = '$_POST[email]' and password = '$_POST[password]'";
$result = mysql_query($query, $con);
$num_rows = mysql_num_rows($result);
$record = mysql_fetch_array($result);
if ($num_rows > 0) {
session_start();
$_SESSION['email'] = $_POST['email'];
$_SESSION['password'] = $_POST['password'];
header("Location: home.php");
}
else
{
echo "<h3><br><br><font>Error in Password or email </font><br> <br>
<font>
if you are new plz register here </a> <br></font>";
echo "</h3>";
}
} else{ echo "<h3><br><br> You Enter any thing , Try again<br> <br> ;}
?>
If user are enters the correct email and password, will get this:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\vwl\login.php:122) in C:\wamp\www\vwl\login.php on line 170
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\vwl\login.php:122) in C:\wamp\www\vwl\login.php on line 174
The code that prints welcome when he enters successfully is:
<?php
// session_start();
//connect to db
if (isset($_COOKIE["email"]) && isset($_COOKIE["password"])) {
$query = "select * from users where email = '$_COOKIE[email]' and password = '$_COOKIE[password]'";
} else {
$query = "select * from users where email='$_SESSION[email]' and password='$_SESSION[password]'";
}
$result = mysql_query($query, $con);
echo "<table border = 0>";
$record = mysql_fetch_array($result);
if ($record) {
echo "<tr><td>$record[email]</td>
<td>
</td></tr><br><br>";
} else {
header("Location: login.php");
}
echo "</table>";
?>