hi guyz, i have a difficulty in understanding the header function. they said that you must first call the header function before any output on the page will make?is that right?
because i create a simple login which when the user click the button submit the query for searching of registered user will execute and will redirect to index.php.after i click the submit here is the error that give's me Warning: Cannot modify header information - headers already sent by (output started at C:\kamote\HelloDatabase2.php:6) in C:\kamote\HelloDatabase2.php on line 65
HERE IS MY CODE
[PHP]<HTML>
<HEAD>
<TITLE>New Document</TITLE>
</HEAD>
<BODY>
<?
if (!isset($_POST['submit'])) {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border=0 cellspacing=10 align=center width=100%>
<tr>
<td align=center style="font-size:50px; background-color:#284775; color:#eeeeee">Login</td>
</tr>
<tr>
<td>
<table border=0 width=50% align=center>
<tr>
<td colspan=2> </td>
</tr>
<tr>
<td colspan=2 style="background-color:#5d7b9d;color:#ffffff;font-weight:bold">Login status:</td>
</tr>
<tr>
<td align="right">Username:</td>
<td><input type="text" name="tusername" size="40">
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="password" name="tpassword" size="40">
</tr>
<tr>
<td></td>
<td><a href="#">Forgot your password?</a> <a href="#">Register?</a></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Login"></td>
</td>
</table>
</td>
</tr>
</table>
<p align=center style="font-size:9pt">Copyright Microkups Co, Inc. © 2007</p>
</form>
<?
}
else {
$server = "localhost";
$user = "root";
$pass = "";
$db = "mydbase";
$uname = $_POST['tusername'];
$upass = $_POST['tpassword'];
$connection = mysql_connect($server,$user,$pass) or die("Unable to connect");
mysql_select_db($db);
$query = "Select * from tblUsers Where username = '$uname' and password = '$upass'";
$result = mysql_query($query) or die("Error in query");
if (mysql_num_rows($result) > 0) {
echo "you successfully logged as $uname";
header ('Location: index.php');
}
else {
echo "invalid username or password";
}
}
?>
</BODY>
</HTML>[/PHP]