Note that there are some explanatory texts on larger screens.

plurals
  1. POUnknown column '(value)' in 'field list'
    text
    copied!<p>Ok, maybe I am a fool, but I can't find out whats wrong here. :)</p> <p>I get this error</p> <blockquote> <p>Unknown column '(the value user has selected from the dropdown)' in 'field list'</p> </blockquote> <p>Yes, I know that this question has been asked many times before, and I have tried to fix my problem with the old answers, but I can't figure it out. I'm trying to make a posting form for a forum and my error is because of the "Select topic type" dropdown menu.</p> <pre><code> &lt;?php //create_topic.php include 'connect.php'; include 'header.php'; echo '&lt;h2&gt;Create a topic&lt;/h2&gt;'; if($_SESSION['signed_in'] == false) { //the user is not signed in echo 'Sorry, you have to be &lt;a href="/forum/signin.php"&gt;signed in&lt;/a&gt; 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 '&lt;form method="post" action=""&gt; Subject: &lt;input type="text" name="topic_subject" /&gt;&lt;br /&gt; Category:'; echo '&lt;select name="topic_cat"&gt;'; while($row = mysql_fetch_assoc($result)) { echo '&lt;option value="' . $row['cat_id'] . '"&gt;' . $row['cat_name'] . '&lt;/option&gt;'; } echo '&lt;/select&gt;&lt;br /&gt; &lt;select name="topic_type"&gt; &lt;option value="Q&amp;A"&gt;Q&amp;A&lt;/option&gt; &lt;option value="Development"&gt;Development&lt;/option&gt; &lt;option value="Rooting and tweeking"&gt;Rooting and tweeking&lt;/option&gt; &lt;option value="Other"&gt;Other&lt;/option&gt; &lt;/select&gt;&lt;br /&gt;'; echo 'Message: &lt;br /&gt;&lt;textarea name="post_content" /&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt; &lt;input type="submit" value="Create topic" /&gt; &lt;/form&gt;'; } } } 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.&lt;br /&gt;&lt;br /&gt;' . 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.&lt;br /&gt;&lt;br /&gt;' . 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 &lt;a href="topic.php?id='. $topicid . '"&gt;your new topic&lt;/a&gt;.'; } } } } } include 'footer.php'; ?&gt; </code></pre> <p><strong>Table structure</strong></p> <p><em>posts</em></p> <p>Kolonne Type Null Standard Kommentarer post_id int(8) Nei<br> post_content text Nei<br> post_date datetime Nei<br> post_topic int(8) Nei<br> post_by int(8) Nei<br> post_type varchar(255) Nei </p> <p><em>topics</em></p> <p>Kolonne Type Null Standard Linker til Kommentarer topic_id int(8) Nei<br> topic_subject varchar(255) Nei<br> topic_date datetime Nei<br> topic_cat int(8) Nei categories -> cat_id<br> topic_by int(8) Nei<br> topic_type varchar(100) Nei </p> <p>(In Norwegian, but I think you will understand) Thanks :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload