Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL和查询无法从PHP文件工作_Php_Mysql - Fatal编程技术网

MySQL和查询无法从PHP文件工作

MySQL和查询无法从PHP文件工作,php,mysql,Php,Mysql,这真的让我很烦,因为我已经在phpmyadmin中实现了这一点,但在我的php脚本中无法实现 下面的代码是一个基本的php文件(我正在学习),其中用户以某种形式提交零件号和订单号,然后将其传递给查询(通过变量),并将查询结果返回到同一页面中的表中 当只传递部分变量$input时,我可以让它正常工作,但当我传递AND条件时,不会返回任何结果。我已经检查并再次检查了表格,测试的组合应该可以工作。我尝试过硬编码一个零件号和订单号的组合,同样的情况也发生了(仅零件可以,但添加和部分时不行)。在phpmy

这真的让我很烦,因为我已经在phpmyadmin中实现了这一点,但在我的php脚本中无法实现

下面的代码是一个基本的php文件(我正在学习),其中用户以某种形式提交零件号和订单号,然后将其传递给查询(通过变量),并将查询结果返回到同一页面中的表中

当只传递部分变量$input时,我可以让它正常工作,但当我传递AND条件时,不会返回任何结果。我已经检查并再次检查了表格,测试的组合应该可以工作。我尝试过硬编码一个零件号和订单号的组合,同样的情况也发生了(仅零件可以,但添加和部分时不行)。在phpmyadmin上测试此部件和订单组合可获得预期效果。我错过什么了吗

<?php include 'database.php' ; ?>

<?php
$input =$_GET['part'];
$ord = $_GET['order'];
// This query works fine with just the $input criteria but when I add AND 'Order' etc... it produces zero results.
$query = "SELECT * FROM `part_status` WHERE `Part` = '$input' AND `Order` = '$ord'";
$result = $conn->query($query);
$status = $result->fetch_assoc();
?>

<!DOCTYPE html>
<html>
<head>
    <title>Part Archive</title>
</head>
<body>

<!-- Form for submitting the two criteria of the query -->
<form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
    Part Number: <input type="text" name="part" value="<?php echo $part;?>" placeholder="Enter part number">
    Order: <input type="text" name="order" value="<?php echo $order;?>" placeholder="Enter order number">
    <input type="submit">
</form>

<header><h1>Orders For: <?php echo $input;?></h1></header>

<!-- Table for displaying the result of the slq query at the top -->
<table>
    <tr><th>Part</th><th>Qty</th><th>Due Date</th><th>Order No.</th></tr>
    <?php while($row = $result->fetch_assoc()) : ?>
        <tr><td><?php echo $row['Part']; ?></td><td><?php echo $row['Qty']; ?></td><td><?php echo $row['Due Date']; ?></td><td><?php echo $row['Order']; ?></td></tr>
    <?php endwhile ;?>
</table>

</body>
</html>


感谢您的指点和建议。

感谢@dbarthel提供此解决方案…

我删除了
$status=$result->fetch_assoc()
和while循环将
替换为
是否检查了
$ord
是否保存了它应该保存的值?我唯一看到的是$status=$result->fetch_assoc(),它将获取第一行(我不知道您的db类,所以我只是猜测)。因此,如果您有1行返回,它将不显示任何内容。表单使用$order而不是$ord作为输入框的值检查输入是否符合您的期望,以及
插值后的
$query
,方法是使用:
var\u dump($\u GET['part'],$\u GET['order'],$query,\uuuuu FILE.\uuuuuu行\)$query=…
语句之后的code>。它应该与您在
phpmyadmin
中使用的查询完全相同?您希望返回多少行?什么是
$status=$result->fetch_assoc()返回?你似乎没有使用它。i、 e.
var\u dump($status,\u FILE.\u LINE\u)