0

SORRY FRIENDS FOR THIS QUESTION, I TESTED THE SAME CODE IN REAL TIME SERVER. IT WORKED FINE, BUT WHEN THE CODE RETURN IN PHPSTORM IT NOT WORKED. (don't know exactly what the reason )

First.php

<form action="second.php" method="post" >
    Name: <input  type="text" name="name" >
    <input type="submit">
</form>

second.php

<?php
if(isset($_POST["name"])){
    $username = $_POST["name"];
    echo $username;
}else
{
    echo "null value";
}
?>

Here i am getting null value. dont know what the reson.


but i simple testing this will GET (where method="get") and second.php is

<?php
echo $_GET["name"];
?>

it worked well.

bhv
  • 5,188
  • 3
  • 35
  • 44
  • 1
    That code seems to work for me? Is error reporting enabled and showing anything? – Script47 Aug 20 '16 at 12:38
  • What just `echo var_dump($_POST);` gives you? – Hardy Aug 20 '16 at 12:38
  • That sounds strange.. have you tried to print_r($_POST); in second.php ? – Bolli Aug 20 '16 at 12:39
  • What if you add `isset` check on submit button (add the name property to it)? – Script47 Aug 20 '16 at 12:42
  • This code is working for me – Zain Farooq Aug 20 '16 at 12:43
  • Have you written correct `action` in form tag – Zain Farooq Aug 20 '16 at 12:43
  • check $_request for above – Rahul Pawar Aug 20 '16 at 12:52
  • 1
    Your code works for me. Maybe a PHP config issue? [Some ideas here](http://stackoverflow.com/questions/1282909/php-post-array-empty-upon-form-submission) – Don't Panic Aug 20 '16 at 13:50
  • @Script47, sorry friends, just now tested in real time server it worked fine, but when i tested in phpStorm its not working – bhv Aug 21 '16 at 03:46
  • @Don'tPanic sorry friends, just now tested in real time server it worked fine, but when i tested in phpStorm its not working – bhv Aug 21 '16 at 03:46
  • @bhv does your first.php correctly firing a post request on submit ?. – RanjanaLK Aug 21 '16 at 04:07
  • @RanjanaLK . yeah it working fine.. but in second.php post is not getting any value.. ( i just tested the same code in other server its worked fine. bu t when i write this code using phpStorm in localhost it not working ) – bhv Aug 21 '16 at 04:11
  • @bhv can you show me the submit request you see on firebug when you are on localhost – RanjanaLK Aug 21 '16 at 04:18
  • @RanjanaLK don't have much knowledge in firebug. is this what you asked me -> body > form > input[type="submit"]:nth-child(2) – bhv Aug 21 '16 at 04:56
  • open first.php on you browser ,open firebug, go to net tab on firebug, then hit the submit button. now you can see the request that came to second.php. if you see a `POST second.php` as the url you have no problem with the request. but if you see `GET second.php?name=something` then you have a problem with your request – RanjanaLK Aug 21 '16 at 06:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/121448/discussion-between-ranjanalk-and-bhv). – RanjanaLK Aug 21 '16 at 06:59

1 Answers1

0

Try this:

HTML

<form action="second.php" method="post" >
Name: <input  type="text" name="name" >
<input type="submit">

PHP

<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
    $username = $_POST["name"];
    echo $username;
}else
{
    echo "null value";
}
?>
Zain Farooq
  • 2,956
  • 3
  • 20
  • 42