Post method not working in PHP

微笑、不失礼 提交于 2021-02-07 19:42:02

问题


I've tried some other posts, but never made it.

My php form inside html file is :

<form action="test.php" method="POST">
VAR:<input type="text" name="var"><br>
<input type="submit">
</form>

I'm receiving the variable in test.php as <br>

$_POST['var'] ---- > doesn't work! <br>

Tried, $_REQUEST['var'] ----> doesn't work!

I tried the form using get request, it works like a charm on the other end at test.php by using both $_GET['var'] and $_REQUEST['var'] Any way I can parse the request in the form of post request from that form to test.php ..

Appreciate the help! Thanks.


回答1:


Did you check the value of 'submit' whether it is set or not like

if(isset($_POST['submit'])){
$_POST['var']
}



回答2:


Updated to PHP 7.0 and it's working now!

Thanks everyone for their help!




回答3:


Your html tag is wrong. You need to set name to it like this

<input type= "submit" name= "submit">

Then when you submit your form like this:

if(isset($_POST['submit'])) {
// you will set your post var, try to print it with
print_r($_POST);

}

And you don't need to add "/" to the input, it will work without it.

And sorry, ive made syntax mistake, forgot to close if statement. Now is correct.




回答4:


Try this what is post on same page

<?php
if(isset($_POST['var_name'])) {
 print_r($_POST);
}
exit();
?>

<form action="" method="POST">
<input type="text" name="var_name"><br>
<input type="submit" name="Save">
</form>


来源:https://stackoverflow.com/questions/34461000/post-method-not-working-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!