php - 插入数据库时​​查询错误

标签 php mysql

我只是想将一些变量插入到数据库中。连接有效,但我不断收到查询错误。

这是 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);

如有任何帮助,我们将不胜感激。提前致谢。

最佳答案

转义 reserved word - ToFrom

$query = "INSERT INTO cards (fromemail, `from`, `to`, toemail, message, stamp) VALUES 
           ('$fromemail', '$from', '$to', '$toemail', '$message', 'now()' )";

关于php - 插入数据库时​​查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8410115/

相关文章:

php - MySQL 按日期和月内整数排序

php - RasPi上php5与mysql连接错误

mysql - Linux MySql 拒绝用户访问

mysql - 如何根据分数获取特定行数

php - magento升级后出现MySQL错误

php - Paypal 编程

php - 条件where子句和mysql参数

php - 如何使用 Ajax 将多个列值从 Mysql 获取到 JQuery 函数中

mysql - Django : OneToOne field links to id and not to email

mysql - 在循环中从数据库中获取数据