简体   繁体   English

PHP 不会通过 POST 传递变量

[英]PHP won't pass a variable through POST

I am having a issue where my PHP code isn't passing the variable in the input.我有一个问题,我的 PHP 代码没有在输入中传递变量。 The value outputs as just a string of "<?php echo $orderID?>" .该值仅输出为字符串"<?php echo $orderID?>" What I would like it to do actually send the variable created.我希望它实际发送创建的变量。

<?php 
if ($order['status'] != "Received") {
    $orderID = $order['orderID'];
    var_dump($orderID);
    echo '<td><form action="./markAsReceived.php" method="POST">
          <input type="hidden" name="orderID" value="<?php echo $orderID; ?>">
          <input type="submit" class="btn btn-secondary mx-1" value="Mark As Received">
          </form></td>';
} else {
    echo '<td></td>';
}
?>

So from this the code checks the database if an Orders status does not equal Received then it displays a button so you can mark it received otherwise it displays nothing.因此,如果订单状态不等于已接收,则代码将检查数据库,然后它会显示一个按钮,以便您可以将其标记为已接收,否则它不会显示任何内容。 The button does appear but like I said before the value for the button is just the string of the php code.按钮确实出现了,但就像我之前所说的,按钮的值只是 php 代码的字符串。

I'm sure it's something simple and I just can't wrap my mind around it, thank you in advance for the help!我确定这很简单,我无法完全理解它,提前感谢您的帮助!

You are not using correct string concatenation.您没有使用正确的字符串连接。 In double quotes, php looks for variables, but in single quotes it doesn't.在双引号中,php 查找变量,但在单引号中不查找。 As you are using html that uses double quotes, single quotes have to be used for your string.由于您使用的是使用双引号的 html,因此您的字符串必须使用单引号。 You can concatenate within a string:您可以在字符串中连接:

<?php 
if ($order['status'] != "Received") {
$orderID = $order['orderID'];
var_dump($orderID);
echo '<td><form action="./markAsReceived.php" method="POST">
      <input type="hidden" name="orderID" value="'.$orderID.'">
      <input type="submit" class="btn btn-secondary mx-1" value="Mark As Received">
      </form></td>';
} else {
echo '<td></td>';
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM