簡體   English   中英

列計數與第1行錯誤處的值計數不匹配

[英]Column count doesn't match value count at row 1 error

我在以下代碼的標題中收到錯誤消息,該頁面用於向我的論壇添加子類別。

<?php

include '../includes/connect.php';
include '../header.php';

echo '<h2>Create a Sub category</h2>';
if($_SESSION['signed_in'] == false | $_SESSION['user_level'] != 1 )
{
//the user is not an admin
echo 'Sorry, you do not have sufficient rights to access this page.';
}
else
{
//the user has admin rights
if($_SERVER['REQUEST_METHOD'] != 'POST')
{
    //the form hasn't been posted yet, display it
    echo '<form method="post" action="">
        Category name: ';
        $sql = "SELECT cat_id, cat_name, cat_description FROM categories";
        $result = mysql_query($sql);
    echo '<select name="topic_cat">';
                while($row = mysql_fetch_assoc($result))
                {
                    echo '<option value="' . $row['cat_id'] . '">' . $row['cat_name'] . '</option>';
                }
            echo '</select><br />';


    echo 'Sub category name: <input type="text" name="sub_cat_name" /><br />
        Sub category description:<br /> <textarea name="sub_desc" /></textarea><br /><br />
        <input type="submit" value="Add Sub Category" />
     </form>';
}
else
{
    //the form has been posted, so save it
    $sql = "INSERT INTO subcategories(c_id, sub_cat_name, sub_desc)
       VALUES('" . $cat_id . ", " . $sub_cat_name . ", " . $sub_desc . "')";
    $result = mysql_query($sql) or die (mysql_error());
    echo 'The sub category <b>" . $sub_cat_name . "</b> has been added under the main category <b>" . $cat_name . "</b>';
    if(!$result)
    {
        //something went wrong, display the error
        echo 'Error' . mysql_error();
    }
    else
    {
        echo 'New Sub category succesfully added.';
    }
}
}
; ?>

我的類別表的結構如下:

  • cat_id
  • cat_desc

我的子類別表的結構如下:

  • id(AI)
  • c_id
  • sub_cat_name
  • sub_desc

如果我沒有提供足夠的信息,請告訴我。

你錯過了一些報價。 更改

VALUES('" . $cat_id . ", " . $sub_cat_name . ", " . $sub_desc . "')";

VALUES('" . $cat_id . "', '" . $sub_cat_name . "', '" . $sub_desc . "')";

您在此處未正確引用:

VALUES('" . $cat_id . ", " . $sub_cat_name . ", " . $sub_desc . "')";

你需要

VALUES('" . $cat_id . "', '" . $sub_cat_name . "', '" . $sub_desc . "')";

請注意額外的單引號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM