Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP$\u POST不适用于HTML表单_Php_Html - Fatal编程技术网

PHP$\u POST不适用于HTML表单

PHP$\u POST不适用于HTML表单,php,html,Php,Html,我是php的初学者。我试图为我的网站创建一个简单的表单,但它似乎不起作用 这是我的php测试代码 <?php var_dump($_POST); var_dump($_GET); var_dump($_REQUEST); ?> 为什么当我在其中输入值时它会返回空字符串?它应该只在表单数据发布时才起作用。试试- <?php $errors = ''; if (!empty($_POST['nameInput']) || !empty($_POST['emailInput'])

我是php的初学者。我试图为我的网站创建一个简单的表单,但它似乎不起作用

这是我的php测试代码

<?php
var_dump($_POST);
var_dump($_GET);
var_dump($_REQUEST);
?>

为什么当我在其中输入值时它会返回空字符串?

它应该只在表单数据发布时才起作用。试试-

<?php 
$errors = '';
if (!empty($_POST['nameInput']) || !empty($_POST['emailInput']) || !empty($_POST['messageInput'])) {
    $name = $_POST['nameInput']; 
    $email_address = $_POST['emailInput']; 
    $message = $_POST['messageInput']; 
    if(!filter_var($email_address, FILTER_VALIDATE_EMAIL)) {
        $errors .= "\n Error: Invalid email address $email_address. name is:".$name."- $message";
    }  
}


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
    <title>Message Submitted</title>
</head>

<body>
<?php
echo $errors;
?>


</body>
</html>

提交的邮件

并且应该检查有效的电子邮件。

您的PHP版本比PHP4.1.0旧!
更新您的PHP。

FYI:如果您不确定Get或Post,请使用$\u REQUEST[“”];但是您定义了方法post,然后就可以使用$u post[''];您是否尝试打印$\u POST以验证您在其中得到了什么?您可以通过检查ThisSet($\u POST['emailInput'])来检查变量是否已设置,以确保您的表单运行正常。打印($\u POST)并查看您在POST请求中收到了什么如果我打印($\u POST),我会得到以下信息:“数组([nameInput]=>[emailInput]=>[messageInput]=>)1”所有表单值都设置为“test”,然后打印($\u POST['nameInput']),我只得到:“1”
array (size=3)
  'nameInput' => string '' (length=0)
  'emailInput' => string '' (length=0)
  'messageInput' => string '' (length=0)

array (size=0)
  empty

array (size=3)
  'nameInput' => string '' (length=0)
  'emailInput' => string '' (length=0)
  'messageInput' => string '' (length=0)
<?php 
$errors = '';
if (!empty($_POST['nameInput']) || !empty($_POST['emailInput']) || !empty($_POST['messageInput'])) {
    $name = $_POST['nameInput']; 
    $email_address = $_POST['emailInput']; 
    $message = $_POST['messageInput']; 
    if(!filter_var($email_address, FILTER_VALIDATE_EMAIL)) {
        $errors .= "\n Error: Invalid email address $email_address. name is:".$name."- $message";
    }  
}


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
    <title>Message Submitted</title>
</head>

<body>
<?php
echo $errors;
?>


</body>
</html>