PHP error

Associate
Joined
19 Oct 2005
Posts
528
Im trying to create a log in script but when i run it i get this error.

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/monkey/public_html/login.php:8) in /home/monkey/public_html/login.php on line 9

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/monkey/public_html/login.php:8) in /home/monkey/public_html/login.php on line 9


The code i am using is this i have changed it to refer to my database and forms. thankyou for any help.

Code:
<?php
// we must never forget to start the session
session_start();

$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
   include 'library/config.php';
   include 'library/opendb.php';

   $userId = $_POST['txtUserId'];
   $password = $_POST['txtPassword'];

   // check if the user id and password combination exist in database
   $sql = "SELECT user_id
           FROM tbl_auth_user
           WHERE user_id = '$userId'
                 AND user_password = PASSWORD('$password')";

   $result = mysql_query($sql)
             or die('Query failed. ' . mysql_error());

   if (mysql_num_rows($result) == 1) {
      // the user id and password match,
      // set the session
      $_SESSION['db_is_logged_in'] = true;

      // after login we move to the main page
      header('Location: main.php');
      exit;
   } else {
      $errorMessage = 'Sorry, wrong user id / password';
   }

   include 'library/closedb.php';
}
?>
 
Back
Top Bottom