Hi
I'm having a bit of a problem with a login page that is supposed to take users to a different page after depending on info from a database. I am using the following code to do this:
foreach ($HTTP_POST_VARS as $key => $value)
$query = "SELECT UserName, Password FROM customer WHERE UserName = '$POST[UserName]' AND Password = '$POST[Password]'";
$result = mysql_query ($query)
or die ("Couldn't execute query.");
$username = $POST['UserName'];
$password = $POST['Password'];
$count = mysql_num_rows($result);
if ($count > 0)
{
echo "Welcome $username<br>";
update_login_table();
login_page();
$login = "yes";
}
else
{
echo "Your username or password is invalid. Please try again.";
}
function login_page()
{
$username = $_POST['UserName'];
$host="localhost";
$connect = mysql_connect($host,"","")
or die ("Couldn't connect to server.");
$db = mysql_select_db("liveweb", $connect)
or die ("Couldn't connect to database.");
$sql1 = "SELECT InterestsID FROM customer_interests WHERE UserName = '$username'";
$query1 = mysql_query ($sql1)
or die ("Couldn't execute query.".mysql_error());
$row = mysql_fetch_array($query1);
extract($row);
if ($InterestsID == 1)
{
header ("Location: mylivedrama.php");
}
else if ($InterestsID == 5)
{
header ("Location: mylivejhc.php");
}
else
{
header ("Location: whatson.php");
}
return;
}
Although this works in that it checks the login and lets people login if username and password are correct, it doesn't then redirect people to a page like it should. Instead it gives the following error:
Couldn't execute query.Duplicate entry '(username)' for key 1
I have no idea why its doing this as I have had it working before and can't remember changing anything. Any help would be greatly appreciated.