misslois74
Programmer
im encountering a problem on the page im working right now in which it should be redirected to a new page, whenever im using the header(Location...) im encountering an error message which is:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\wppp\login.php:6) in C:\xampp\htdocs\wppp\login.php on line 171
im using wamp server before and i never encounter this problem but right now im running it in xampp and having this problem....
here is my code:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\wppp\login.php:6) in C:\xampp\htdocs\wppp\login.php on line 171
im using wamp server before and i never encounter this problem but right now im running it in xampp and having this problem....
here is my code:
Code:
<?php
$errors=array();
if(isset($_REQUEST['submit']))
{
validate_input();
if(count($errors) != 0)
{
display_form();
}
if(count($errors) == 0)
{
include "connection_dbase_settings.php";
$user_name = $_POST['username'];
$pass_word = $_POST['password'];
$result1 = mysql_query("Select * from tbl_users where username='$user_name' and password='$pass_word'") or die(mysql_error());
$num = mysql_num_rows($result1);
<?php }
if($num != 0)
{
header("Location: [URL unfurl="true"]http://www.yahoo.com");[/URL]
}
else
{
header("Location: [URL unfurl="true"]http://www.google.com");[/URL]
}
}
}
else
{
display_form();
}
function validate_input()
{
global $errors;
if($_POST['username'] == "")
{
$errors['username'] = "<font color='red' size='1'>* Username required</font>";
}
if($_POST['password'] == "")
{
$errors['password'] = "<font color='red' size='1'>* Password required</font>";
}
}
function display_form()
{
global $errors;
?>
<?php echo $errors['username']; ?><br />
<?php echo $errors['password']; ?><br />
<center>
<br /><table width=351 border="1" bordercolor="#e6cda5" cellspacing="2" cellpadding="2">
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<tr>
<td width=113 height="24" class="t_table">Username:</td>
<!--width="23%" width="41%"width="37%"-->
<td width=218 class="t_table"><input type="text" name="username" value="<?php echo $_POST['username'] ?>" size=30/></td>
</tr>
<tr>
<td width=113 height="24" class="t_table">Password:</td>
<td><input type="password" name="password" value="<?php echo $_POST['password'] ?>" size=30/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Submit" /> <input type="reset" value="Clear" /></td>
</tr>
</form>
</table>
<?php } ?>