這是我的第一頁,這將是我的登錄頁面。在他們的用戶名,用戶類型,點擊登錄,然後broswer應該帶他們去的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>
當用戶點擊提交就會去的login.php,看起來像這樣:
<?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"]);
}
?>
哪一個不工作,我不明白爲什麼。它只是彈出一個解析錯誤:語法錯誤,意外的T_VARIABLE在.... myfile ....在第一次嘗試和使用$ _POST變量行。順便說一下,我正在login.php頂部導入的DataBaseConnection.php中開始我的會話。
你的問題是不是真的與你的問題。你的PHP腳本的語法有問題。您需要發佈確切的錯誤消息。 – six8
您在'$ stmt = $ DBH-> prepare(「SELECT * FROM QuizUser where Name =?」)後面缺少分號' – six8
謝謝,我補充說,但仍然沒有解決任何問題。 – Tombo890