redirect to new page using php
Hi I'm having problems trying to redirect to another page using php. My code is pure php - no html before the script but I keep getting errors. The code is:
<?php
session_start(); // start the session
$errorMessage = '';
if (isset($_POST['userName']) && isset($_POST['pWord'])) {
ob_start();
include 'library/config.php';
include 'library/opendb.php';
$userId = $_POST['userName'];
$password = $_POST['pWord'];
// check if the user id and password combination exist in database
$sql = "SELECT userId FROM auth_user WHERE userId = '$userId' AND userPWord = '$password'";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
// if the user id and password match, 1 row at least will be returned
if (mysql_num_rows($result) == 1) {
// set the session
$_SESSION['db_is_logged_in'] = true;
// after login we move to the main page
ob_end_flush();
header('Location:http://localhost/morindacards/mainAmend.php');
//echo "we're in";
exit;
}
else{
$errorMessage = 'Sorry, wrong user id / password ';
$echo $errorMessage;
}
include 'library/closedb.php';
}
?>
the errors are:
Warning: Cannot modify header information - headers already sent by (output started at c:\Inetpub\wwwroot\...
Can anyone help? This is driving me nuts.
G
|