Hi, I am very new to PHP and so far I must admit that I like it 🙂
However I'm having some difficulty with one little issue and any help would be appreciated.
Here is my code (Borrowed and modified by myself for my needs)
<?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) {
header("Location: http://www.corkboot.net/index.html");
exit;
} else {
setcookie("loggedin", "TRUE", time()+(3600 * 24));
setcookie("mysite_username", "$username");
header("Location: http://www.corkboot.net/members.html");
}
?>
So this code actually does what I want it to do, it automatically forwards failed passwords back to the index and forwards successes to the members. However in doing this I have no way of informing the user of their failed login, it just reloads the page. I know that using header means that it has to be the first thing sent to browser (I am correct in this, right?) so is there a way to send extra data with the header to allow the user to know the login failed?
I have an idea to simply make an exact copy of index.html and call it indexfailed.html and simply add some extra text to the login box stating that login failed but that seems like a duct tape solution, I would really prefer to learn to code it properly.
Thanks so much
Thomas