无法使用PHP获取表单数据

时间:2015-11-28 22:41:57

标签: php

嘿,所有我可以告诉我的代码看起来它应该有效,但事实并非如此。我没有看到我的错误在哪里。当我填写表格并按提交时,我能够获得名称的第一个变量,但电话和电子邮件不会显示。有人能指出我的错误在哪里吗?     `          表格测试     

<body>

<form action="clientData.php" method="post">
What is your name?
<input type="text" name="name">

<br>
What is your email address?
<input type ="text" email="email">

<br>
What is your phone number?
<input type = "text" phone="phone">
</br>
<input type="submit">


</form>
</body>
</html>`

这是我的clientData.php文件,我想将我的变量存储到我的数据库中。

<?php $clientName= $_POST['name']; $clientEmail= $_POST['email']; echo $clientName; echo $clientEmail; ?>

3 个答案:

答案 0 :(得分:2)

您需要像这样更改表单:

<form action="clientData.php" method="post">
What is your name?
<input type="text" name="name">

<br>
What is your email address?
<input type="text" name="email">

<br>
What is your phone number?
<input type="text" name="phone">
</br>
<input type="submit">

PHP:

<?php
$clientName= $_POST['name'];
$clientEmail= $_POST['email'];
$clientPhone= $_POST['phone'];
?>

定义HTML数组中值的索引的POST属性为name,因此例如要创建一个字段,您需要这样做:

<input type="text" name="theNameOfTheField">

要在PHP中获得结果:

<?php
$fieldValue= $_POST['theNameOfTheField'];
?>

答案 1 :(得分:1)

<input type ="text" name="email" id="name">

如果你没有为这个元素命名,那么它就不会有效。

答案 2 :(得分:1)

What is your email address?
<input type ="text" email="email">

<br>
What is your phone number?
<input type = "text" phone="phone">

这里的错误是输入名称应该是name而不是字段名称

What is your email address?
<input type ="text" name="email">

<br>
What is your phone number?
<input type = "text" name="phone">