有人可以帮我解决这个mysql查询

时间:2015-04-22 17:22:46

标签: php mysql

  

您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在附近使用')'

$sql = "INSERT INTO 
                    topics(topic_subject,
                           topic_date,
                           topic_cat,
                           topic_by)
               VALUES('" . mysql_real_escape_string($_POST['topic_subject']) . "',
                           NOW(),
                           " . mysql_real_escape_string($_POST['topic_cat']) . ",
                           " . $_SESSION['fullname'] . "
                           )";

3 个答案:

答案 0 :(得分:1)

你缺少字符串值的引号这里是你的新sql

ql = "INSERT INTO 
                        topics(topic_subject,
                               topic_date,
                               topic_cat,
                               topic_by)
                   VALUES('" . mysql_real_escape_string($_POST['topic_subject']) . "',
                               NOW(),
                               '" . mysql_real_escape_string($_POST['topic_cat']) . "',
                               '" . $_SESSION['fullname'] . "'
                               )";

答案 1 :(得分:1)

你需要在存储为VARCHAR的值周围加上引号,我想在这种情况下$_SESSION['fullname']。像这样:

$sql = "INSERT INTO 
                    topics(topic_subject,
                           topic_date,
                           topic_cat,
                           topic_by)
               VALUES('" . mysql_real_escape_string($_POST['topic_subject']) . "',
                           NOW(),
                           " . mysql_real_escape_string($_POST['topic_cat']) . ",
                           '" . $_SESSION['fullname'] . "'
                           )";

答案 2 :(得分:1)

尝试以下方法:

你错过了单引号。

 $sql = "INSERT INTO 
                topics(topic_subject,
                       topic_date,
                       topic_cat,
                       topic_by)
           VALUES('" . mysql_real_escape_string($_POST['topic_subject']) . "',
                       NOW(),
                       '" . mysql_real_escape_string($_POST['topic_cat']) . "',
                       '" . $_SESSION['fullname'] . "'
                       )";