page navigation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
madu
Forum Commoner
Posts: 32
Joined: Sat Dec 25, 2010 3:19 am
Location: india

page navigation

Post 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
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: page navigation

Post by social_experiment »

Create a function.

Code: Select all

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

 //other code
 echo "loggin success";
 loggedInUser();
 exit();
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: page navigation

Post 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....
Post Reply