php接收不到post发送的值(新手问题)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php接收不到post发送的值(新手问题)相关的知识,希望对你有一定的参考价值。

1.4.php
<html>
<head>
<title>Figure1.4</title>
</head>
<body>
<form action="1-5.php" method="get">
your Name:<input type="text" name="YourName"><br>
Cost of a Lunch:<input type="text" name="CostOfLunch"><br>
Days Buying Lunch:<input type="text" name="DaysBuyingLunch"><br>
<input type="submit">
</form>
</body>

</html>

1.5.php

<body>
Today's Date:
<?
/*print today's date*/
print("<H3>$Today</H3>\n");
Print("$YourName,you will be out ");
print($CostOfLunch * $DaysBuyingLunch);
print(" dollars this week.<br>\n");
?>

</body>

我用get方法已经看到参数在地址栏 但是就是接收不到 为什麽啊?

参考技术A 在你的php中要先声明一下:
$YourName=$_POST['YourName'];
其他几个同样

$_POST['YourName'];
这个是获取post传递信息的方式

楼上说的$_GET['']方式,是获取url传递的变量
参考技术B 在你的1.5.php的php代码里面加上
$Today=$_REQUEST[Today];
$YourName=$_REQUEST[YourName];
$CostOfLunch=$_REQUEST[CostOfLunch];
$DaysBuyingLunch=$_REQUEST[DaysBuyingLunch];
就可以了
参考技术C 你用$_GET['yourname']这样才能取到值,如果是POST方法就用$_POST['yourname']这种方法取值 参考技术D 改一下你的form
<form action="1-5.php" method="post"> <---- 这里是POST而不是GET
your Name:<input type="text" name="YourName"><br>
Cost of a Lunch:<input type="text" name="CostOfLunch"><br>
Days Buying Lunch:<input type="text" name="DaysBuyingLunch"><br>
<input type="submit">
第5个回答  2009-01-15 <?
$YourName=$HTTP_GET_VARS['YourName'];
或者
<?
$YourName=$_GET['YourName'];本回答被提问者采纳

PHP为啥接收不到POST 的数据?

<form name = "name1" action="welcome.php" method="post">
Enter your name: <input type="text" name="name" />
Enter your age: <input type="text" name="age" />
<input type="submit" />
</form>

Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!
------------------------------------------
<html>
<body>

<form action="welcome.php" method="post">
Enter your name: <input type="text" name="name" />
Enter your age: <input type="text" name="age" />
<input type="submit" />
</form>

</body>
</html>
-------------------------
<html>
<body>

Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!

</body>
</html>

第一个页面

第二个 可以接受post  没错啊 你具体什么问题 我运行是可以接收的

追问



Enter your name:
Enter your age:

追答

在welcome.php 中写入
Welcome .
You are years old!
写进去就好了 是没跳转链接吗

追问



Welcome .
You are years old!

这样吗 ? 因为我是自学的 不知道对不对

追答

对的 不写body和html也没事的 试试可以不 你写好了welcome.php 之前的那个页面按提交就可以进入这个页面了 会显示信息了

追问

提交之后过来就变成

去掉之后的结果就变成这样了

追答

你用记事本那加上去 我们用编程软件自带了 你最好下个软件方便点 txt那只有老老实实来 不过新学的话建议还是老实多写写 养成好习惯

追问

我就是用两个记事本写的   HTML 和PHP的代码都在上门了 


输出不出来结果   很无语 


 加了 body和html 的结果是 

Welcome .
You are years old!



没加的结果是 

追答

那只能说是不是环境问题了,这个完全没问题。

追问

怎么检测环境?

追答

你自己装的吗?是linux还是window 我是apache+php+mysql+phpadmin 你里面的配置文件对吗 有配置吗

追问

WINDOW XAMPP

参考技术A

好吧,可能是你的这个文件不是welcome.php

 就改一下你的代码

----------------------------------------

好吧我就再改一下代码吧;

index.htm

<form name = "name1" action="test.php" method="post">
Enter your name: <input type="text" name="name" />
Enter your age: <input type="text" name="age" />
<input type="submit" />
</form>

test.php

Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!

 

追问

一样的结果 还是不可以。 是不是环境问题 ?

追答

你输出下面的页面

info.php

<?php phpinfo();?>

看一下能不能输出你的PHP信息;

如果不能,说明环境是有问题的;

---------------------

还有一个问题就是打开方法的问题;

如果是本地的话;地址是

http://localhost/info.php

不是d:/php/inof.php这样子的;这种方法是不会运行PHP的;

追问

结果:
和明确的就是环境问题, 求解决

追答

还有一个问题就是打开方法的问题;

如果是本地的话;地址是
http://localhost/info.php
不是d:/php/inof.php这样子的;这种方法是不会运行PHP的;

本回答被提问者采纳
参考技术B 你的代码无问题,从login.php跳转到welcome.php
login.php / login.html
<html>
<form action="welcome.php" method="post">
Enter your name: <input type="text" name="name" />
Enter your age: <input type="text" name="age" />
<input type="submit" />
</form>
</html>

welcome.php [只有下面两条语句,不要多写]
Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!

运行即正确的值。
welcome.php最好改为:【规范】
<?php
echo "Welcome ".$_POST["name"]."<br/>";
echo "You are ".$_POST["age"]." years old!";
?>追问

还是显示的和截图一下差不过的结果:

";
echo "You are ".$_POST["age"]." years old!";
?>

我觉得可能不是代码的问题。 我觉得高手换换思路看看能不能解决问题?

追答

我运行没有错,现在把文件传给你,你试一下我的代码。

welcome.php

<?php
 echo "Welcome ".$_POST["name"]."<br/>";
 echo "You are ".$_POST["age"]." years old!";
?>



参考技术C 你不贴代码谁知道,你如果是from表单提交。就好好看看文档,你要是ajax 提交一样好看看 参考技术D 从代码上看不出有什么问题

以上是关于php接收不到post发送的值(新手问题)的主要内容,如果未能解决你的问题,请参考以下文章

接收不到shopify webhook 发送post请求

Post无法将数据发送到php文件[php新手]

PHP为啥接收不到POST 的数据?

xmlhttp用post发送请求,但是servlet接收到的request里面,获取不到参数

后端接收不到AngularJs中$http.post发送的数据的问题

微信小程序接受不到POST的值