Jump to content


This topic is now archived and is closed to further replies.


Login Script Problem...

Recommended Posts

Please could you help?  Here is my script:

// start the session

$errorMessage = '';
if ( (isset($_POST['username'])) && (isset($_POST['password'])) ) {
  include '../db/config.php';
  include '../db/opendb.php';

  $username = $_POST['username'];
  $password = $_POST['password'];
  $password_hashed = md5($password);

  // check if the user id and password combination exist in database
  $sql = "SELECT *
  FROM accounts
  WHERE username = '$username'
  AND password = '$password_hashed' ";

  $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
  while ($member_details_array = mysql_fetch_assoc($result)) {

$member_id = $member_details_array['member_id'];

$_SESSION[$member_id] = true;

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

  include '../db/closedb.php';

It seems to do all the db stuff ok, logs the user in but I get this error:

Cannot modify header information - headers already sent by ...

Many Thanks in advance for your help.

Regards and Jesus Christ's blessings,

Chris Cundill

Share this post

Link to post
Share on other sites
Fixed it sorry to bother you.

For the benefit of the community it was blank lines after my closing ?> and the beginning of my html!

Thats all!

Share this post

Link to post
Share on other sites
sometimes it's better to get more sessions set ok like.


then in the future you can use them ok.

good luck.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.