I am writing a code in which I have 2 files index.php and register.php.
index.php contains the code for html form which is given below:
<form action="register.php" method="POST">
<fieldset>
<legend>Personal Information</legend>
First Name: <input type="text" name="fname">
<br>
<br>
Last Name: <input type="text" name="lname">
<br>
<br>
<input type="submit" name="submit" value="Submit">
</fieldset>
</form>
register.php have the following code:
<?php
//if(isset($_POST['fname']))
{
$f_name= $_POST['fname'];
}
//if(isset($_POST['lname']))
{
$l_name = $_POST['lname'];
}
echo $f_name;
echo "<br><br>";
echo $l_name;
?>
I've written the code in PhpStorm and I also have Xampp installed in my windows 10 installed system. I have set 'htdocs' directory of xampp as 'apache_http_server' in 'D:\' drive of my system and also create PhpStorm project in the sub directory of 'apache_http_server' so that I can run my php project using Xampp and PhpStorm IDE. I also set the php innterpreter supplied with Xampp as the default interpreter of PhpStorm so in both case my code uses same interpreter (PHP Version 7.0.4).
Now the problem is whenever I run this project using Xampp it runs without any kind of error and notice. but if I run the same project using PhpStorm IDE using its inbuilt httpserver on port 63342 its gives me following notice as o/p:
Notice: Undefined index: fname in D:\practice\apache_http_server\my_projects\login_form\register.php on line 5
Notice: Undefined index: lname in D:\practice\apache_http_server\my_projects\login_form\register.php on line 10
I also tried to solve this notice by using if(isset()) as per another answers on stackoverflow but it leads to the undefined variable error.
So why this happens ? where is problem occurs? Am I missed to make change in any configuration file? if yes than what changes need or where?
The o/p screenshots using Xampp server and PhpStorm are as follows:
- Using Xampp the final O/p:
- O/P with notice by PhpStorm's http server: