未定义变量:$_post xampp 服务器

问题描述 投票:0回答:1

我尝试运行此代码,但得到的输出是:

注意:未定义的变量:_post 在 E:\xampp\htdocs estphp.php 第 4 行

注意:未定义的变量:_post 在 E:\xampp\htdocs estphp.php 第 5 行

注意:未定义的变量:_post 位于 E:\xampp\htdocs estphp.php 第 6 行

名字:- 姓氏:- 其他详细信息:

这是我表单的代码:

<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>

这是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>

请帮助我!

php post xampp
1个回答
1
投票

我只是将这个确切的代码复制粘贴到我的系统中,它工作得很好。

从错误消息看来,您似乎从不同的 html 文件调用了 testphp.php。请确保在浏览器中运行之前保存了更改...这两个文件。

代码没有任何问题,我只是复制粘贴,没有任何修改,效果很好。

有时问题可能出在您的 PHP 配置文件上。请验证您的 PHP 配置文件是否启用了超全局变量。设置开发服务器的最佳方法是单独安装 Apache、PHP 和 MySQL,而不是使用所有软件包。这使您可以全面了解您的配置,并且可以快速排除此类错误。

我有过一次经历,由于病毒,rename(); php 中的函数从未工作过,但重新安装 Windows 后,它无需任何修改即可工作。因此,请验证您的操作系统是否有任何问题。尝试使用相同的设置在其他系统中执行您的代码(我坚持使用此解决方案,因为您的代码在我的系统!!)

© www.soinside.com 2019 - 2024. All rights reserved.