我试图根据位置从数据库中显示此表信息,但不管是什么电子邮件ID,它只显示来自lacion牛津的数据。任何人都可以让我知道我是新来的代码有什么问题,并试图获得一些expirience手 提前致谢 这是我的代码片段
<?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 = "oxford@connectone.com")
{
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 = "bridgport@connectone.com")
{
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";
} ?>
答案 0 :(得分:2)
您在if语句中分配值:
if ($email = "oxford@connectone.com")
分配值时,将返回赋值("oxford@connectone.com"
)。这个字符串是&#34; truthy&#34; (评估为true
),以便第一个if
语句运行,并忽略所有else
。
您应该使用comparison operator - ==
或===
。
if ($email === "oxford@connectone.com") { //... }
elseif ($email === "bridgport@connectone.com") { //... }