Warning: Cannot modify header information - headers already sent
Im sure you have all seen this before, so have i! But i cant see why this is happening as i use the header function in my shopping cart in a similar manner and it causes no problems!
heres my code
//Checks given username and password againts database
function username_password()
{
if (isset($_POST['username']) && ($_POST['password']))
{
$p_username = $_POST['username'];
$p_password = $_POST['password'];
$invalid = "yes";
mysql_connect("localhost", "xxxxxx", "xxxx") or die(mysql_error());
mysql_select_db("xxxxx") or die(mysql_error());
$result = mysql_query("SELECT * FROM customers") or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$username = $row['username'];
$password = $row['password'];
if (($p_username == $username) && ($p_password == $password))
{
$_SESSION['user']['validID'] = "ok";
$_SESSION['user']['name'] = $row['forename'];
$_SESSION['user']['userID'] = $row['userID'];
$invalid = "no";
header('location: other_page.php');
//echo "hello you!";
}
}
if ($invalid == "yes")
{echo "you have supplied an invalid username and password";}
}
}
and the next page which calls the function:
<?php
session_start();
require_once("functions.library.php");
$username_password = username_password();
echo $username_password;
?>
<form method='post' action='index.php'>
<input type='text' name='username' size='25'><p>
<input type='text' name='password' size='25'><p>
<input type='submit' name='submit' value='Login'>
</form>
thanks in advance, i can see it being a really simple solution!