錯誤:解析錯誤:語法錯誤,意想不到的T_ENCAPSED_AND_WHITESPACE,期待T_STRING或T_VARIABLE或T_NUM_STRING線路7PDO查詢是否有重複的用戶名在提交
嘗試使用PDO
,使這個連接,形成查詢如果按下提交後輸入字段,則檢查用戶名是否存在。
HTML:
<form action="inc/check_regUsr.php" method="post" id="userLogon">
<div class="field required">
Username: <input type="text" name="regduser" tabindex="1" /><br />
</div>
<div class="field required">
Password: <input type="password" name="regdpass" tabindex="2" /><br />
</div>
<input type="submit" name="submitUser" />
</form>
PHP
<?php
#Login Details
require_once('dbcred.php');
$conn = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
#Check for Existing User
$q = $conn->query("SELECT uname FROM Student WHERE $_POST['regduser'] = uname");
$stmt = $conn->prepare($q);
$r->execute($q);
if($q($r)>= 1){ #if there are 1 or more users with enter username, deny.
echo "Sorry, username already exists";
}
else{
echo "Success";
}
?>
請閱讀SQL注入。 –