为什么在我的代码中接收_post不起作用

时间:2021-10-10 20:19:23

I am trying to make a form and I want to handle it but I couldn't.

我正在尝试制作一个表格,我想处理它,但我不能。

Here is the form from myhome.php.

这是myhome.php的表格。

<form method="post" action="upload.php" enctype="multipart/form-data">    <br>
        <img  id="im" src="pic.png" width="30" height="30" />
        <input type="image"  id="su"   " src="sent.png" width="50" height="50" />
        <input type="file" id="my_file" style="display: none;" />
        <input type="submit" id="submit" value="fileToUpload" style="display: none;" name="submit"/>       
</form>

I am using jQuery to connect the pictures to the inputs.

我正在使用jQuery将图片连接到输入。

The problem is that I can't receive the data in upload.php - it gives me an empty _post['submit'] .

问题是我无法在upload.php中收到数据 - 它给了我一个空_post ['submit']。

upload.php:

    <?php

if(isset($_POST["submit"])) {

        echo "its not empty " ;

    } else {
        echo "error";

    }

?>

3 个解决方案

#1


When you submit the form, the action file upload.php will receive key=>value variable pairs from each element in the form.

提交表单时,操作文件upload.php将从表单中的每个元素接收key => value变量对。

The name of each received variable will be the name="somename" HTML attribute of each element.

每个接收变量的名称将是每个元素的name =“somename”HTML属性。

So, just add a name="somehting" to your input elements.

所以,只需在输入元素中添加一个名称=“somehting”即可。

 <input name="fname" type="text" />

Then, on the PHP side:

然后,在PHP方面:

$fn = $_POST['fname'];

And you got it.

你明白了

#2


Remove style="display: none;" from submit button and give it opacity 0 instead

删除style =“display:none;”从提交按钮,而不是给它不透明度0

#3


Change

<input type="image"  id="su"   " src="sent.png" width="50" height="50" />

To

<input type="image"  id="su"    src="sent.png" width="50" height="50" />

After that on next page (upload.php) first try

之后在下一页(upload.php)上先试试

echo "<pre>"; print_r($_POST); echo "</pre>"; 

This will give an out of all the post values you are getting .

这将给出您获得的所有帖子值。

#1


When you submit the form, the action file upload.php will receive key=>value variable pairs from each element in the form.

提交表单时,操作文件upload.php将从表单中的每个元素接收key => value变量对。

The name of each received variable will be the name="somename" HTML attribute of each element.

每个接收变量的名称将是每个元素的name =“somename”HTML属性。

So, just add a name="somehting" to your input elements.

所以,只需在输入元素中添加一个名称=“somehting”即可。

 <input name="fname" type="text" />

Then, on the PHP side:

然后,在PHP方面:

$fn = $_POST['fname'];

And you got it.

你明白了

#2


Remove style="display: none;" from submit button and give it opacity 0 instead

删除style =“display:none;”从提交按钮,而不是给它不透明度0

#3


Change

<input type="image"  id="su"   " src="sent.png" width="50" height="50" />

To

<input type="image"  id="su"    src="sent.png" width="50" height="50" />

After that on next page (upload.php) first try

之后在下一页(upload.php)上先试试

echo "<pre>"; print_r($_POST); echo "</pre>"; 

This will give an out of all the post values you are getting .

这将给出您获得的所有帖子值。