This is my first page, which would be my login page. The user types in their username, hits login, and then the broswer should take them to login.php Index.html
<html>
<head>
<title>Login</title>
</head>
<body >
<br><br><br><br><h2 align=center>Quiz Taker</h2>
<br><br><br>
<p align=center></p>
<br>
<form method="post" action="login.php">
<table class="login" cellpadding=10 cellspacing=0 align="center" bgcolor="#cccccc" border="3">
<tr>
<td>
<input type="radio" name="userType" value="Student"/> Student
<input type="radio" name="userType" value="Teacher"/> Teacher
<td>
Username:</td><td><input type="text" name="username" size=10>
</td>
</tr>
<tr>
<td colspan=2 align="center">
<input type="submit" name="submit" value=" Log In ">
</td>
</tr>
</table>
</form>
</body>
</html>
When the user hits submit it will go to login.php which looks like this:
<?php
include_once("DatabaseConnection.php");
$stmt=$DBH->prepare("SELECT * FROM QuizUser where Name=?")
$stmt->bindValue(1, $_POST['username']);
$stmt->execute();
if ($row=$stmt->fetch())
{
$ID=$row['ID'];
}
else
{
$stmt=$DBH->prepare("INSERT INTO QuizUser(Name) VALUES(?)")
$stmt->bindValue(1, $_POST['username']);
$stmt->execute();
$ID=$DBH->lastInsertId();
}
$_SESSION['userID']= $ID;
$_SESSION['userName']= $_POST['username'];
$_SESSION['userType']=$_POST['userType'];
if($_POST['userType'] == "Student")
{
header($string["Location:student.php"]);
}
else
{
header($string["Location:teacher.php"]);
}
?>
Which is not working and I cannot figure out why. It just pops up a parse error: syntax error, unexpected T_VARIABLE in ....myfile.... at line whever the first time I try and use the $_POST variable. By the way, I am starting my session in the DataBaseConnection.php that is imported at the top of login.php.