Hey, im pretty new to PHP and my problem is, when people try to log on to my website, if the username and password is correct it will say welcome $username so thats ok, but the problem is that when it isnt correct username and password, it doesnt show the error message, its jus blank. here is the code, if anyone has any ideas please reply.
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?
$conn = mysql_connect("localhost","USERNAME","PASSWORD");
$db = mysql_select_db("DATABASENAME");
$result = MYSQL_QUERY("SELECT username, password from users WHERE username='$username'and password='$password'") or die ("Name and password not found or not matched");
$worked = mysql_fetch_array($result);
$user = $worked[name];
$password = $worked[password];
if($worked)
echo "Welcome $username";
} else {
echo "error"';
}
?>
</body>
</html>if ($worked = mysql_fetch_array($result))
{
$user = $worked[name];
$password = $worked[password];
echo "Welcome $user";
} else {
ps. you didn't have an { for the if
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?
$conn = mysql_connect("localhost","USERNAME","PASSWORD");
$db = mysql_select_db("DATABASENAME");
$result = MYSQL_QUERY("SELECT username, password from users WHERE username='$username'and password='$password'") or die ("Name and password not found or not matched");
$worked = mysql_fetch_array($result);
$user = $worked[name];
$password = $worked[password];
if($worked)
echo "Welcome $username";
} else {
echo "error"';
}
?>
</body>
</html>if ($worked = mysql_fetch_array($result))
{
$user = $worked[name];
$password = $worked[password];
echo "Welcome $user";
} else {
ps. you didn't have an { for the if