I tried to make a simple login from, and here is what I have. But whenever I try to open the file on my site, it gives me a 500 error.
Code:
<!DOCTYPE html PUBLIC>
<html>
<head>
<meta charset="utf-8" />
<title>Login</title>
<body>
<?php
$host = "localhost";
$user = "(My username)";
$pass = "(my password)";
$db = "(My database name)";
if {isset($_POST['username'])) {
mysql_connect($host, $user, $pass);
mysql_select_db($db);
$username = $_POST['username'];
$password = $_POST['password'];
$sql = SELECT * FROM users WHERE username'".$username."' AND password='".$password."' LIMIT 1";
$res = mysql_query($sql);
if {mysql_num_rows($res) == 1) {
echo "You have successfully logged in.";
exit();
} else }
echo "Invalid login info.";
exit();
}
}
?>
<form method="post" action="login.php">
Username: <input type="text" name="username" /><br /><br />
Password: <input type="password" name="password" /><br /><br />
<input type="submit" name="submit" value="Log In" />
</form>
</body>
</html>
Anyone know how I can fix this?
Code:
<!DOCTYPE html PUBLIC>
<html>
<head>
<meta charset="utf-8" />
<title>Login</title>
<body>
<?php
$host = "localhost";
$user = "(My username)";
$pass = "(my password)";
$db = "(My database name)";
if {isset($_POST['username'])) {
mysql_connect($host, $user, $pass);
mysql_select_db($db);
$username = $_POST['username'];
$password = $_POST['password'];
$sql = SELECT * FROM users WHERE username'".$username."' AND password='".$password."' LIMIT 1";
$res = mysql_query($sql);
if {mysql_num_rows($res) == 1) {
echo "You have successfully logged in.";
exit();
} else }
echo "Invalid login info.";
exit();
}
}
?>
<form method="post" action="login.php">
Username: <input type="text" name="username" /><br /><br />
Password: <input type="password" name="password" /><br /><br />
<input type="submit" name="submit" value="Log In" />
</form>
</body>
</html>
Anyone know how I can fix this?