I’m trying to make a basic user login. In the PHP page that logs the user In I’m getting errors. It works, but has errors at the top of the page. I’m using:
UPDATE:
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if ($username && $password)
{
$connect = mysql_connect('hidden') or die ('could not connect');
mysql_select_db('hidden') or die ('could not connect to the database');
$query = mysql_query("SELECT * FROM users WHERE username = '$username'");
$num_rows = mysql_num_rows($query);
if ($num_rows!=0)
{
//code to login
while ($row = mysql_fetch_assoc ($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
//check to see if username/password match
if ($username==$dbusername && $password==$dbpassword)
{
echo "You're in! <a href=\"member.php\">Click here</a> to enter the member area";
$_SESSION['username'] = $username;
}
else
echo "Incorrect username/password";
}
else
die('That user does not exist');
}
else
die('Please enter a username/password');
?>
This is the error if it helps:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/16/7554016/html/grahamcaldwell/DrumChum/login.php:6) in /home/content/16/7554016/html/grahamcaldwell/DrumChum/login.php on line 16
UPDATE
Problem solved. I had to put session_start(); before even the DOCTYPE.
The issue with the session is probably because of the warning about the unexpected character. Maybe that warning is causing output to be sent to the buffer which is triggering the session error.