php - Unknown column '(value)' in 'field list' -


ok, maybe fool, can't find out whats wrong here. :)

i error

unknown column '(the value user has selected dropdown)' in 'field list'

yes, know question has been asked many times before, , have tried fix problem old answers, can't figure out. i'm trying make posting form forum , error because of "select topic type" dropdown menu.

 <?php //create_topic.php include 'connect.php'; include 'header.php';  echo '<h2>create topic</h2>'; if($_session['signed_in'] == false) {     //the user not signed in     echo 'sorry, have <a href="/forum/signin.php">signed in</a> create topic.'; } else {     //the user signed in     if($_server['request_method'] != 'post')     {            //the form hasn't been posted yet, display         //retrieve categories database use in dropdown         $sql = "select                     cat_id,                     cat_name,                     cat_description                                     categories";          $result = mysql_query($sql);          if(!$result)         {             //the query failed, uh-oh :-(             echo 'error while selecting database. please try again later.';         }         else         {             if(mysql_num_rows($result) == 0)             {                 //there no categories, topic can't posted                 if($_session['user_level'] == 1)                 {                     echo 'you have not created categories yet.';                 }                 else                 {                     echo 'before can post topic, must wait admin create 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 , tweeking">rooting , 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 transaction         $query  = "begin work;";         $result = mysql_query($query);          if(!$result)         {             //damn! query failed, quit             echo 'an error occured while creating topic. please try again later.';         }         else         {              //the form has been posted, save             //insert topic topics table first, we'll save post posts table             $sql = "insert                          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 error                 echo 'an error occured while inserting data. please try again later.<br /><br />' . mysql_error();                 $sql = "rollback;";                 $result = mysql_query($sql);             }             else             {                 //the first query worked, start second, posts query                 //retrieve id of freshly created topic usage in posts query                 $topicid = mysql_insert_id();                  $sql = "insert                             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 error                     echo 'an error occured while inserting post. please try again later.<br /><br />' . mysql_error();                     $sql = "rollback;";                     $result = mysql_query($sql);                 }                 else                 {                     $sql = "commit;";                     $result = mysql_query($sql);                      //after lot of work, query succeeded!                     echo 'you have succesfully created <a href="topic.php?id='. $topicid . '">your new topic</a>.';                 }             }         }     } }  include 'footer.php'; ?> 

table structure

posts

kolonne type null standard kommentarer post_id int(8) nei
post_content text nei
post_date datetime nei
post_topic int(8) nei
post_by int(8) nei
post_type varchar(255) nei

topics

kolonne type null standard linker til kommentarer topic_id int(8) nei
topic_subject varchar(255) nei
topic_date datetime nei
topic_cat int(8) nei categories -> cat_id
topic_by int(8) nei
topic_type varchar(100) nei

(in norwegian, think understand) :)

by way...

topic_type seems string should put in quotes in insert query:

 $sql = "insert             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']) . "'           )"; 

maybe thats reason errror.

i saw post_type string, too. same in second insert query!


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -