我正在输入'add poll'模块形式的文本框,我正在创建 我正在添加的民意调查答案选择是,否,可能。
不,也许被抓住,但是省略了,这是第一个答案?
我相信这是经过多次故障排除后的问题。
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");
}
}
}
答案 0 :(得分: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");
}
}
}