3

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.

marekful
  • 14,986
  • 6
  • 37
  • 59
Ninja Boy
  • 1,112
  • 3
  • 14
  • 28

4 Answers4

0

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

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

Updated to PHP 7.0 and it's working now!

Thanks everyone for their help!

Ninja Boy
  • 1,112
  • 3
  • 14
  • 28
-1

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.

fugitive
  • 357
  • 2
  • 8
  • 26
  • Sorry for being so lame, but should i add thatif(isset_ .. in test.php? If yeah, where? Sorry again, I'm very new to php.. – Ninja Boy Dec 25 '15 at 08:01
  • Well.. yes.. that way you basicly check is submit button pressed.. And that way you submit form, and process it to "test.php" – fugitive Dec 25 '15 at 08:03
  • Also @pbssubhash you access every form value in php with name atribute in html. On the side.. Who the hell gave me -1 for answer, because it is correct?? – fugitive Dec 25 '15 at 08:06
  • Oh, I didn't mark -1 , BTW, The post works like charm with GET method. Does that change anything? – Ninja Boy Dec 25 '15 at 08:07
  • @pbssubhash well if you wanna use get, you need to change html, so method="GET" Difference between POST and GET, is that, get vals will be in url, while post wont. Sorry Im little in hurry so this is rough explanation. Cheers. – fugitive Dec 25 '15 at 08:11
  • Yeah I know, When I'm using method as get , I was able to parse the parameters correctly. But when I try with POSt changing the method to post, it doesn't work. In a secure point of view,I don't want sensitive info in the url as params – Ninja Boy Dec 25 '15 at 08:12
-1

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>
Alfiza malek
  • 994
  • 1
  • 14
  • 36