Хорошо, может быть, я дурак, но я не могу понять, что здесь не так. :)Неизвестный столбец '(значение)' в 'списке полей'
Я получаю эту ошибку
Неизвестный столбец «(пользователь выбрал значение из выпадающего списка)» в «списке поля»
Да, я знаю, что этот вопрос был спросил много раз раньше, и я попытался исправить свою проблему со старыми ответами, но я не могу понять это. Я пытаюсь создать форму для публикации форума, и моя ошибка связана с раскрывающимся меню «Выбрать тип темы».
<?php
//create_topic.php
include 'connect.php';
include 'header.php';
echo '<h2>Create a topic</h2>';
if($_SESSION['signed_in'] == false)
{
//the user is not signed in
echo 'Sorry, you have to be <a href="/forum/signin.php">signed in</a> to create a topic.';
}
else
{
//the user is signed in
if($_SERVER['REQUEST_METHOD'] != 'POST')
{
//the form hasn't been posted yet, display it
//retrieve the categories from the database for use in the dropdown
$sql = "SELECT
cat_id,
cat_name,
cat_description
FROM
categories";
$result = mysql_query($sql);
if(!$result)
{
//the query failed, uh-oh :-(
echo 'Error while selecting from database. Please try again later.';
}
else
{
if(mysql_num_rows($result) == 0)
{
//there are no categories, so a topic can't be posted
if($_SESSION['user_level'] == 1)
{
echo 'You have not created categories yet.';
}
else
{
echo 'Before you can post a topic, you must wait for an admin to create some categories.';
}
}
else
{
echo '<form method="post" action="">
Subject: <input type="text" name="topic_subject" /><br />
Category:';
echo '<select name="topic_cat">';
while($row = mysql_fetch_assoc($result))
{
echo '<option value="' . $row['cat_id'] . '">' . $row['cat_name'] . '</option>';
}
echo '</select><br />
<select name="topic_type">
<option value="Q&A">Q&A</option>
<option value="Development">Development</option>
<option value="Rooting and tweeking">Rooting and tweeking</option>
<option value="Other">Other</option>
</select><br />';
echo 'Message: <br /><textarea name="post_content" /></textarea><br /><br />
<input type="submit" value="Create topic" />
</form>';
}
}
}
else
{
//start the transaction
$query = "BEGIN WORK;";
$result = mysql_query($query);
if(!$result)
{
//Damn! the query failed, quit
echo 'An error occured while creating your topic. Please try again later.';
}
else
{
//the form has been posted, so save it
//insert the topic into the topics table first, then we'll save the post into the posts table
$sql = "INSERT INTO
topics(topic_subject,
topic_date,
topic_cat,
topic_by,
topic_type)
VALUES('" . mysql_real_escape_string($_POST['topic_subject']) . "',
NOW(),
" . mysql_real_escape_string($_POST['topic_cat']) . ",
" . $_SESSION['user_id'] . ",
" . mysql_real_escape_string($_POST['topic_type']) . "
)";
$result = mysql_query($sql);
if(!$result)
{
//something went wrong, display the error
echo 'An error occured while inserting your data. Please try again later.<br /><br />' . mysql_error();
$sql = "ROLLBACK;";
$result = mysql_query($sql);
}
else
{
//the first query worked, now start the second, posts query
//retrieve the id of the freshly created topic for usage in the posts query
$topicid = mysql_insert_id();
$sql = "INSERT INTO
posts(post_content,
post_date,
post_topic,
post_by,
post_type)
VALUES
('" . mysql_real_escape_string($_POST['post_content']) . "',
NOW(),
" . $topicid . ",
" . $_SESSION['user_id'] . "
" . mysql_real_escape_string($_POST['post_type']) . ",
)";
$result = mysql_query($sql);
if(!$result)
{
//something went wrong, display the error
echo 'An error occured while inserting your post. Please try again later.<br /><br />' . mysql_error();
$sql = "ROLLBACK;";
$result = mysql_query($sql);
}
else
{
$sql = "COMMIT;";
$result = mysql_query($sql);
//after a lot of work, the query succeeded!
echo 'You have succesfully created <a href="topic.php?id='. $topicid . '">your new topic</a>.';
}
}
}
}
}
include 'footer.php';
?>
структура таблицы
сообщений
Kolonne Тип Null Стандартный Kommentarer post_id Int (8) Nei
POST_CONTENT текст Nei
POST_DATE DateTime Nei
post_topic INT (8) Nei
post_by INT (8) Nei
post_type VARCHAR (255) Nei
темы
Kolonne Тип Null Стандартный компоновщик сезам Kommentarer topic_id Int (8) Nei
topic_subject VARCHAR (255) Nei
topic_date Дата и время Nei
topic_cat Int (8) Ней категории -> cat_id
topic_by Int (8) Nei
topic_type VARCHAR (100) Nei
(В норвежском, но я думаю, вы поймете) Спасибо :)
Ошибка действительно говорит '' (моя ценность здесь) ''? – OptimusCrime
Это означает, что имена столбцов не соответствуют определению таблицы. Так как вы не дали минимального примера, вам сложно помочь вам в этом. –
Нет, но значение зависит от того, что пользователь выбирает из выпадающего меню :) Я отредактирую его – user1888043