-1
我試圖從數據庫中顯示基於位置的這個表信息,但不管電子郵件地址是什麼,我只能從lacation牛津顯示數據。任何人都可以請讓我知道什麼是錯的我是新來的PHP,並試圖獲得一些雙手的expirience 提前感謝 下面的代碼是我的代碼片段php html數據庫表冗餘
<?php
if (isset($_POST['submitbutton']))
{
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "SELECT email,password from users WHERE email = '".$email."' AND password ='".$password."'";
$result = $conn->query($sql);
if ($email = "[email protected]")
{
echo 'The email is'. $email;
$query = "Select * from stock WHERE location = 'oxford'";
$result1 = $conn->query($query);
if ($result1->num_rows > 0){
?>
<table class="reports">>
<thead>
<tr>
<th> Item name </th>
<th> Price </th>
<th> Quantity </th>
<th> Quantity Damaged </th>
</tr> </thead> <tbody>
<?php
while($row = $result1->fetch_assoc()){
echo
"<tr>
<td>{$row['item_name']}</td>
<td>{$row['price']}</td>
<td>{$row['quantity']}</td>
<td>{$row['quantity_damaged']}</td>
</tr>\n";
} ?> </tbody>
</table>
<?php
}
}
elseif ($email = "[email protected]")
{
echo 'The email is'. $email;
$query1 = "Select * from stock WHERE location = 'bridgeport'";
$resut2 = $conn->query($query1);
if ($result2->num_rows > 0){
?>
<table class="reports">
<thead>
<tr>
<th> Item name </th>
<th> Price </th>
<th> Quantity </th>
<th> Quantity Damaged </th>
</tr> </thead> <tbody>
<?php
while($row = $result2->fetch_assoc()){
echo
"<tr>
<td>{$row['item_name']}</td>
<td>{$row['price']}</td>
<td>{$row['quantity']}</td>
<td>{$row['quantity_damaged']}</td>
</tr>\n";
} ?>
請注意,直接插串到你的查詢('電子郵件=「$電子郵件。」 ...')是極其危險的,你應該瞭解爲什麼這是一個問題:https://開頭計算器。 COM /問題/ 60174 /如何-可以-I-防止-SQL注入式的PHP?RQ = 1。此外,在明文存儲密碼不應該這樣做,你應該使用內置的PHP的密碼散列函數:http://php.net/manual/en/faq.passwords.php – Scopey