因此,我的研究讓我感到這個小問題。 (一直進入php爲一個堅實的一個月,所以我道歉,如果我不完全清楚)匹配數據庫中的所有值的表單值
我有一個小的表格組成的用戶名和通行證。
<form method="post" action="proc.php">
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="user" id="user"></td>
</tr>
<tr>
<td>password:</td>
<td><input type="text" name="password" id="password"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="submit"></td>
</tr>
</table>
</form>
我在db列中有相應的值。
即時嘗試要做的是,即時嘗試檢查所輸入的名稱在表單字段與數據庫列的期望值。
所以當我做這個測試在DB只是一個值(第一個值正弦其不循環),它的工作原理,讓我在:
$dbq = "SELECT * FROM accounts;";
$dbqDoIt = mysqli_query($connect2db, $dbq)or die("error".mysqli_error($connect2db));
$getNames = mysqli_fetch_array($dbqDoIt);
//check if user acc. exists inside vSpot database.
if(($name !== $getNames['username']) || ($pass !== $getNames['password'])){
header("Location:index.php"); /* Redirect browser */
測試我的while循環... (導致即時新的大聲笑),當我這樣做:
$nums = array(1,2,3,4,5);
for($i=0; $i<6; $i++){
if($nums[0] < 6) echo $i . '<br/>';
}
它的工作原理和列出數字1-5。
現在,當我嘗試通過數據庫名稱/通過循環,它不起作用。 像這樣:
while($getNames = mysqli_fetch_array($dbqDoIt)){
//check if user acc. exists inside my database.
if(($name !== $getNames['username']) || ($pass !== $getNames['password'])){
header("Location:index.php"); /* Redirect them to log in */
}
}
任何想法,爲什麼它不檢查,對所有的值?即時消息確定我錯過了什麼大聲笑。
任何提示,建議等不愉快欣賞。 謝謝你advace
somdow。
客戶端篩選...啊...你應該閱讀約佔['哪裏'](http://en.wikipedia.org/wiki/Where_%28SQL%29)SQL查詢中的子句。 –
除非我錯過了一些東西,不應該使用一個簡單的'WHERE username ='$ username''爲你工作嗎? – jprofitt