Page 1 of 1

page navigation

Posted: Fri Dec 31, 2010 4:05 am
by madu
<html>
<body>
<div style="position:absolute;top:150px;left:780px">
<table border=0>
<form method=post action="<?php echo $_SERVER['PHP_SELF']; ?>">
<tr>
<td>User Name:<input type=text name=uname>
</tr>
<tr>
<td>Password: &nbsp; <input type=password name=pwd>
</tr>
<tr>
<td>
<center><input type=submit name=sub value=submit></center>
</td>
</tr>
</form>
</div>
<?php
if(isset($_POST['sub']))
$uname=$_POST['uname'];

$pwd=$_POST['pwd'];

$con=mysql_connect("localhost","root","");

mysql_select_db("my_db",$con);

$result=mysql_query("select * from logi where uname='$uname' and pwd='$pwd'");

$num=mysql_num_rows($result);

if($num<1)
{
echo "login failed";
}
else
{
echo "loggin success";

header('Location: newmob.php');
//exit();
}

}
?>
here login is success but when i try to move next page it showed error cant change header,,,,,,,,,,,,,help pls

Re: page navigation

Posted: Fri Dec 31, 2010 6:44 am
by social_experiment
Create a function.

Code: Select all

<?php
 function loggedInUser() {
  header('location: newmob.php');
 }

 //other code
 echo "loggin success";
 loggedInUser();
 exit();
?>

Re: page navigation

Posted: Fri Dec 31, 2010 9:54 am
by anantha
since you are echoing out before....whether it is success or failure...the headers are sent at that time...so you must figure out a way to echo after the header redirect....you can use output buffering or some other way....