I have a PHP register form and every time I enter a name and password into the form it says "unexpected $end on line 52". The code is below for the index:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="handler.php" method="post">
<h1>Register</h1>
<input type="text" name="username" /><br />
<input type="password" name="password" /><br />
<input type="submit" value="submit" />
</form>
</body>
</html>
handler:
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$counter = 0;
class MyDB extends SQLite3
{
function __construct()
{
$this->open('db/test.db');
}
}
$db = new MyDB();
$sql =<<<EOF
SELECT username from users WHERE username='$username';
EOF;
$ret = $db->query($sql);
while($row = $ret->fetchArray(SQLITE3_ASSOC)){
$counter++;
}
if($counter >= 1){
echo "user already exists. click <a href='index.php'>here </a> to go back";
}
if($counter = 0){
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$sql2 =<<<EOF
INSERT INTO users(ID, username, password) VALUES (null, '$username', '$password');
EOF;
header('Location: index.php');
}
?>
</body>
</html>