[英]Trouble Feeding Variables from a Form into a PHP Script Using the “$_POST” Command
我在将变量从html表单输入到php中时遇到了一些困难。 有人介意帮助我,我已经在这里工作了几个小时。
HTML代码:
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Welcome to Chorelistings - Log in Here</title>
<!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body>
<form action="test.php" class="login">
<h1>Chore Listings </h1>
<input type = "email" id="email" name = "email" class = "login-input" placeholder = "Username (Email)">
<input type="password" name="password " id ="password" class="login-input" placeholder="Password">
<input type="submit" value="Login" class="login-submit">
<p class="create-account"><a href="register.html">Create Account</a></p>
<p class="login-help"><a href="index.html">Forgot password?</a></p>
</form>
</body>
</html>
我的非常简单的php脚本:
<?php
$email=$_POST['email'];
echo "hi";
?>
您的表单上没有method
,因此默认为GET,它不会发送$_POST
值。
将method="post"
添加到您的<form>
标记中。
这里有几件事。 您的表单未指定请求方法。 将method
属性添加到表单标签中,如下所示:
<form method="post" action="test.php" class="login">
接下来,只是一个注释,在指定属性时不需要空格,例如:
<input type = "email" id="email" name = "email" class = "login-input" placeholder = "Username (Email)" />
您将可以搭配使用:
<input type="email" id="email" name="email" class="login-input" placeholder="Username (Email)" />
需要考虑的一些(较不常见)的事情-确保您的.htaccess
不会以不需要的方式重写任何发布请求。 如果您碰巧在表单中上传了任何文件,请确保在表单上指定enctype
属性,例如:
enctype="multipart/form-data"
祝你好运!
首先,尝试将method="post"
添加到<form>
标签:
<form action="test.php" class="login" method="post">
其次,在您的test.php
文件中,尝试调试实际发送的内容:
<?php
print_r($_POST);
// or
var_dump($_POST);
// or for more info
print_r($_REQUEST);
?>
第三,尝试在html中定义输入字段时删除空格:
<input type="email" id="email" name="email" class="login-input" placeholder="Username (Email)">
最后,在关闭</form>
<submit>
之前将<submit>
添加到表单中以实际发布数据。 目前,我看到您有链接( <a href>
),但是不会提交该表单。
因此,最终的html应该看起来像(简化)一样:
<form method="post" action="test.php">
<input type="text" name="email">
<submit>
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.