Hi!
I have read through the forums, but was unable to find an answer to my exact problem. I hope someone will help me. I am new to php and I got this code from a tutorial, but it is not working for me. It works when I remove the code for setting cookies, but a login without cookies is pointless. I keep getting the error messages:
Warning: Cannot modify header information - headers already sent by (output started at /home/forceofg/public_html/bookatopia.com/config.php:1) in /home/forceofg/public_html/bookatopia.com/login.php on line 17
Warning: Cannot modify header information - headers already sent by (output started at /home/forceofg/public_html/bookatopia.com/config.php:1) in /home/forceofg/public_html/bookatopia.com/login.php on line 18
You are now logged in!
Continue to the members section.
This is my code:
<?php
include("config.php");
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
$match = "select id from $table where username = '".$_POST['username']."'
and password = '".$_POST['password']."';";
$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows <= 0) {
echo "Sorry, there is no username $username with the specified password.<br>";
echo "<a href=login.html>Try again</a>";
exit;
} else {
setcookie("loggedin", "TRUE", time()+(3600 * 24));
setcookie("mysite_username", "$username");
echo "You are now logged in!<br>";
echo "Continue to the <a href=members.php>members</a> section.";
}
?>
Please help me. Thank you.