gpt4 book ai didi

php - 列计数与第 1 行错误的值计数不匹配

转载 作者:行者123 更新时间:2023-11-30 01:30:50 26 4
gpt4 key购买 nike

我在以下代码的标题中收到错误消息,该页面用于向我的论坛添加子类别。

<?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_desc

如果我没有提供足够的信息,请告诉我。

最佳答案

您在这里没有正确引用内容:

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

你需要

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

注意额外的单引号。

关于php - 列计数与第 1 行错误的值计数不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17480292/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com