这是代码: contact_us2.php
<form id="form1" method="post" action="enquires.php">
<fieldset>
<legend>Form to database example</legend>
<label for="text">
<span>Comments:</span>
<textarea id="text" name="comments" rows="4" cols="80"></textarea>
</label>
<label for="name">
<span>Name:</span>
<input id="name" type='text' name='name' size='50'/>
</label>
<label for="email">
<span>Email:</span>
<input id="email" type='text' name='email' size='50'/>
</label>
<label for="submit1" id="submit"><span> </span>
<input id="submit1" class="submit" type="submit" name="submit" value="Submit"/>
</label>
</fieldset>
</form>
enquires.php
<?php
session_start();
error_reporting(E_ALL & ~E_NOTICE);
require('authenticate.php');
include_once"../scripts/connect_to_mysql.php";
$name = $_post['name'];
$email = $_post['email'];
$comments = $_post['comments'];
echo "$email";
// Query the body section for the proper page
mysql_select_db("hardware_cms" )or die (mysql_error());
$sqlCommand = MYSQL_QUERY("INSERT INTO enquires (id, name, email, comments)". "VALUES ('NULL', '$name', '$email', '$comments')") or die (mysql_error());
?>
没有错误。插入数据库的唯一内容是id。我认为问题出在contact_us2.php中。我是html和php的新手,如果这是一个愚蠢的问题,我很抱歉。
答案 0 :(得分:2)
错误在PHP代码中,因为你必须使用$ _POST而不是$ _post
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
答案 1 :(得分:1)
将$_post
替换为$_POST
,看看会发生什么。
此外,请清理您的SQL输入(通过使用mysql_real_escape_string或更好 - 通过使用PDO预处理语句)。