【发布时间】:2016-05-12 16:08:56
【问题描述】:
我正在尝试比较已导入脚本的 MySQL 表列,并将其与我定义的 PHP 值进行比较。
我正在尝试创建一个 if 循环来检查列中的任何值是否等于变量。
// Connect to database containing order information
$servername = "server";
$username = "user";
$password = "pass";
// Create connection
$conn = new mysqli($servername,$username,$password);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// define variables and set to empty values
$name = $ordernumber = "";
// Load up data from the form
$ordernumber = ($_POST['order_number']);
// Get SQL info
$sql = "SELECT order_number FROM p_orders;";
if ($conn->query($sql) === TRUE)
{
echo "Checked Orders.....";
}
else
{
echo "Failed to check orders, please contact Support for assistance" . $conn->error;
}
// Checking Script
if ($ordernumber === $orders)
{
echo "Order Number Found.... Let's Select a Seat";
}
else
{
echo "Your Order was not found, either you did not order a reservation ticket, have not waited 3 days or you entered the number wrong. If issues persist then please contact Support."
};
【问题讨论】:
-
$orders 是在哪里定义的?我看不到它被定义了
-
为什么不将 WHERE order_number='$ordernumber' 添加到 MySQL 查询中。然后 chk 返回的 num_rows - 如果它是 1 则该订单号存在; 0 它没有。
-
或者尝试通过mysqli_fetch_assoc从数据库中获取order_number
-
尝试使用准备好的语句而不是@user3535901
-
@PeterDarmis 请停止随意提出建议。你完全错了。在这里使用准备好的声明对手头的事情绝对没有影响。