PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
$connect = mysql_connect($host, $user, $pswd)
or die("Could not connect: " . mysql_error());
$database = mysql_select_db('tech_support')
or die(MySQL_Error());
$sql = "SELECT * FROM members";
$result = mysql_query($sql) or die(MySQL_Error());
for ($i = 0; $rows = mysql_fetch_row($result); $i++)
{
if ($rows[1] == $_POST["user"] && $rows[2] == $_POST["password"])
{
print "Good login...i won't kill you<br />";
}else{
print "BAD USER OR PASSWORD YOU LOOSER<br />";
}
}
mysql_close($connect);
?>
that s my code...
now in my if instead of puting Good login.. i want to redirect to a page...
but it : Warning: Cannot add header information - headers already sent
i know that header should be in head (or befor anything else) but still i need to put my redirect in the if... so any suggestion
you could just echo a meta tag to redirect if you're not really trying to be too secure. what's to keep someone from just typing in the page in the address bar from the beginning?
<?php
// pseudo code to give you ideas.
// more security could be nice...
$connect = mysql_connect($host, $user, $pswd) or die("Could not connect: " . mysql_error());
$database = mysql_select_db('tech_support') or die(MySQL_Error());
$sql = "SELECT * FROM members where username = '$_POST[user]' and pass = '$_POST[password]'";
$result = mysql_query($sql) or die(MySQL_Error());
mysql_close($connect);
if (mysql_num_rows($result) == 0) {
header("Location: http://www.example.com/");
exit;
} else {
echo 'Yay!';
}
?>