简体   繁体   中英

Undefined variable: $_post xampp server

I tried to run this code ,but the output I got was:

Notice: Undefined variable: _post in E:\\xampp\\htdocs\\testphp.php on line 4

Notice: Undefined variable: _post in E:\\xampp\\htdocs\\testphp.php on line 5

Notice: Undefined variable: _post in E:\\xampp\\htdocs\\testphp.php on line 6

First Name:- Last Name:- Other Details :

This is the code of my form:

<html>
<body>
<form method="post" action="testphp.php">
<label for="firstname">First Name: </label>
<input type="text" id="firstname" name="firstname" /> </br></br>

<label for="lastname">Last Name: </label>
<input type="text" id="lastname" name="lastname" /> </br></br>

<label for="other"> Other Details: </label>
<textarea name="other" ></textarea></br></br>

<input type="submit" value="Ok -- submit" name=submit  />
</form>

</body>
</html>

This is the code in testphp.php:

<html>
<body>
<?php
$first_name = $_POST['firstname'];
$last_name= $_POST['lastname'];
$otherdetail= $_POST['other'];

echo 'First Name:- '. $first_name;
echo 'Last Name:- '. $last_name;
echo 'Other Details :- '. $otherdetail;

?>
</body>
</html>

Please help me!

I just copy pasted this exact code in my system and it worked fine.

from the error message it seems like you called the testphp.php from a different html file.Make sure you saved the changes before running it in browser...both files.

There is nothing wrong with the code.I just copy pasted without any modification and it worked well.

Sometimes the problem may be with your PHP configuration file.Please verify your PHP configuration file for superglobal variables is enabled or not.The best way to setup a development server is by individullay installing Apache,PHP and MySQL instead of using Packages of all.This gives you a through knowledge of your configurations and you can quickely troubleshoot errors of this sort.

I had an experience where because of a virus the rename(); function in php never worked,but after reinstalling windows it worked without any modifications.So please verify if you have any problem with OS.Try executing your code in other system with the same setup(I insists on this solution because your code worked fine on my system!!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM