0

我正在创建我正在创建的“添加投票”模块表单文本框,并且我添加的投票答案的选择是“是”、“否”、“也许”。

No 和 Maybe 被捕获,但 Yes 被省略,这是第一个答案?

我相信这是经过多次故障排除后的问题线。

for ($i=1; $i <= $number; $i++ )

提交后(来自错误日志):

语句 INSERT INTO db_fpollitems VALUES (NULL, 66, No, 1, 0) 出现数据库错误。错误是:“字段列表”中的未知列“否”

语句 INSERT INTO db_fpollitems VALUES (NULL, 66, Maybe, 2, 0) 出现数据库错误。错误是:“字段列表”中的未知列“可能”

语句 INSERT INTO db_fpollitems VALUES (NULL, 66, , 3, 0) 出现数据库错误。错误是:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '3, 0)' 附近使用正确的语法

如果我更换

"NULL, {$poll['id']}, {$polloptions[$i]}, $i, 0");

"NULL, {$poll['id']}, $i, $i, 0");

它带有明显的 1.2.3 民意调查答案。

这是解决问题的代码。

if ($_POST['submit'] == "Submit" && $word_ok)
{
    $subject = safesql($_POST['subject'], "text");
    $post = safesql($_POST['article'], "text", false);
    $number = $_POST['numoptions'];
            
    $pollquest = safesql($_POST['question'], "text");
    $polloptions = $_POST['option'];
            
    $username = safesql($check['id'], "text");
    
    $sql = $data->insert_query("ftopics", "NULL, $subject, 0 , $username, $timestamp, $username, $timestamp, $type, $fid, 0");
    if ($sql)
    {
        $sql = $data->select_query("ftopics", "WHERE subject=$subject AND numviews=0");
        $topic = $data->fetch_array($sql);
        
        $sql = $data->insert_query("fposts", "NULL, $subject, $post, $username, $timestamp, {$topic['id']}, 0, 0");
        if ($sql)
        {
            $data->update_query("users", "numposts = numposts + 1, numtopics = numtopics + 1", "id='{$check['id']}'");
            
            if ($pollquest != "" && $number > 1)
            {
                $sql = $data->insert_query("fpolls", "NULL, {$topic['id']}, $pollquest");
                if ($sql)
                {
                    $sql = $data->select_query("fpolls", "WHERE topic_id = {$topic['id']} AND question = $pollquest", "id");
                    $poll = $data->fetch_array($sql);
                    for ($i=1; $i <= $number; $i++ )
                    {
                        $data->insert_query("fpollitems", "NULL, {$poll['id']}, {$polloptions[$i]}, $i, 0");
                    }
                }
            }
               
4

1 回答 1

0

您正在插入不带引号的文字,请尝试以下操作:

"NULL, {$poll['id']}, '{$polloptions[$i]}', $i, 0");

你的代码应该是这样的:

if ($_POST['submit'] == "Submit" && $word_ok)
{
    $subject = safesql($_POST['subject'], "text");
    $post = safesql($_POST['article'], "text", false);
    $number = $_POST['numoptions'];

    $pollquest = safesql($_POST['question'], "text");
    $polloptions = $_POST['option'];

    $username = safesql($check['id'], "text");

    $sql = $data->insert_query("ftopics", "NULL, '$subject', 0 , '$username', $timestamp, '$username', $timestamp, '$type', $fid, 0");
    if ($sql)
    {
        $sql = $data->select_query("ftopics", "WHERE subject='$subject' AND numviews=0");
        $topic = $data->fetch_array($sql);

        $sql = $data->insert_query("fposts", "NULL, '$subject', '$post', '$username', $timestamp, {$topic['id']}, 0, 0");
        if ($sql)
        {
            $data->update_query("users", "numposts = numposts + 1, numtopics = numtopics + 1", "id='{$check['id']}'");

            if ($pollquest != "" && $number > 1)
            {
                $sql = $data->insert_query("fpolls", "NULL, {$topic['id']}, '$pollquest'");
                if ($sql)
                {
                    $sql = $data->select_query("fpolls", "WHERE topic_id = {$topic['id']} AND question = '$pollquest'", "id");
                    $poll = $data->fetch_array($sql);
                    for ($i=1; $i <= $number; $i++ )
                    {
                        $data->insert_query("fpollitems", "NULL, {$poll['id']}, '{$polloptions[$i]}', $i, 0");
                    }
                }
            }
于 2013-10-01T11:28:03.360 回答