我只是想将一些变量插入到数据库中。连接有效,但我一直收到查询错误。
这是HTML:
<form action="process-step1.php" method="post">
<div id="fromDiv" class="clearfix">
<h4>Your Name</h4>
<input type="text" name="from" id="from" value="" />
<h4>Your E-mail</h4>
<input type="text" name="fromemail" id="fromemail" value="" />
</div>
<div id="toDiv" class="clearfix">
<h4>Recipient Name</h4>
<input type="text" name="to" id="to" value="" />
<h4>Recipient E-mail</h4>
<input type="text" name="toemail" id="toemail" value="" />
</div>
<div id="messageDiv" class="clearfix">
<h4>Message</h4>
<textarea name="message" id="message"></textarea>
</div>
<div id="submitDiv" class="clearfix">
<input type="submit" value="Preview my Card" name="submit" id="submit" />
</div>
</form>
以下是PHP流程:
$from = mysql_escape_string($_POST['from']);
$fromemail = mysql_escape_string($_POST['fromemail']);
$to = mysql_escape_string($_POST['to']);
$toemail = mysql_escape_string($_POST['toemail']);
$message = mysql_escape_string($_POST['message']);
$query = "INSERT INTO cards (fromemail, from, to, toemail, message, stamp) VALUES ('$fromemail', '$from', '$to', '$toemail', '$message', 'now()' )";
$results = mysql_query($query);
任何帮助将不胜感激。提前谢谢。
答案 0 :(得分:1)
转义reserved字词 - To
和From
。
$query = "INSERT INTO cards (fromemail, `from`, `to`, toemail, message, stamp) VALUES
('$fromemail', '$from', '$to', '$toemail', '$message', 'now()' )";
答案 1 :(得分:0)
试试这个
$query = "INSERT INTO cards (fromemail, from, to, toemail, message, stamp) VALUES ('".$fromemail."', '".$from."', '".$to."', '".$toemail."', '".$message."', '".now()' )";