[RESOLVED] header problem
my site wont redirect using header("Location: whatever");
i don't really know what i'm doing wrong here...
code:
Code:
<?php
$host="localhost";
$username="root";
$password="";
$db_name="admin";
$tbl_name="admin";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$_SESSION["myusername"] = $myusername;
$_SESSION["mypassword"] = $mypassword;
header("location: login_success.php"); //error here line 26
}
else {
echo "Wrong Username or Password";
}
?>
error:
Code:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\xampp\htdocs\tp\checklogin.php:1) in C:\xampp\xampp\htdocs\tp\checklogin.php on line 26
Re: [RESOLVED] header problem
Doesn't really matter where you post the data, as long as you redirect after you receive it. If you do not, the user will get the dreaded "This form must be resubmitted" message if they try to go back after posting the form.
What you should do, whenever handling posted data, is use a 303 status code.
PHP Code:
header('Location: http://example.org/NextPage', true, 303);
Location is an absolute URI.