简体   繁体   English

PHP:通过图像提交按钮传递选择和隐藏输入的值

[英]PHP: passing values of select and hidden input via image submit button

I have a table contains Orders data that was retrieved from a data base and there is a field called "status" contains a form with select options and a hidden input with the value of the order ID.. the issue that the form doesn't seem passing the data to the php file that will run the function. 我有一个表,其中包含从数据库中检索到的订单数据,还有一个名为“状态”的字段,其中包含带有选择选项的表单以及具有订单ID值的隐藏输入。.表单不存在的问题似乎将数据传递到将运行该功能的php文件。

I tried both POST and GET methods and what I noticed that the data are passed in the URL leading to the php file but with blank page. 我尝试了POST和GET方法,发现数据在URL中传递到php文件,但页面空白。

this is the URL to show the parameters: 这是显示参数的URL:

http://localhost/project_name/test2.php?submit.x=15&submit.y=22&status=new&orderId=190406053842

here is my HTML form 这是我的HTML表格

<td>
        <form action="test2.php" method="GET">
        <input type="image" name="submit" src="icons/submit.png" alt="Submit" style='width:30px;height:30px;border:0;' onclick="confirm('are you sure?')"> 
        <select name="status">
            <option value="new">new</option>
            <option value="checking">checking</option>
            <option value="processing">processing</option>
            <option value="done">done</option>
          </select>
          <input type="hidden" name="orderId" value="<?php echo $row["ORDER_ID"]; ?>">
          </form>
</td>

this is the php file (just echoing the result to make sure it works and proceed onwards) 这是php文件(只需回显结果以确保其有效并继续进行)

    <?php
    $db = mysqli_connect('localhost', 'root', '', 'project_name');


            if(isset($_GET['submit'])){
                $status = $_GET['status'];
                $ID = $_GET['orderId'];

    echo $staus;
    echo $ID;
}
    ?>  

thank you. 谢谢。

If you look at your GET URL string there is no 'submit' variable, so checking for a 'submit' variable is not going to work. 如果您查看GET URL字符串,则没有'submit'变量,因此检查'submit'变量将行不通。

It looks like it is appending co-ordinates to the 'submit' variable so its actually outputting 'submit.x' and 'submit.y'. 看起来好像是将坐标附加到“ submit”变量上,因此其实际输出是“ submit.x”和“ submit.y”。 I've never used the image input type before so can only guess this is the intended functionality of this input type. 我以前从未使用过图像输入类型,因此只能猜测这是此输入类型的预期功能。

You could get around this by checking for the 'orderID' instead of 'submit'. 您可以通过检查“ orderID”而不是“ submit”来解决此问题。 Or you could try 'submit.x' or 'submit.y'. 或者,您可以尝试使用“ submit.x”或“ submit.y”。

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

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