title: How do I make it so that the topic_cat= the current category
body: <p>How do I make it so that the topic_cat= the current category, for example <a href="http://prntscr.com/h08ae" rel="nofollow">http://prntscr.com/h08ae</a> I want the category id to insert as the topic_cat. But I when I make the topic it just leads to the category id to =0, Here is my code:</p>
  
  <pre><code> &lt;?php
  
  if($_SESSION['signed_in'] == false)
  {header('Location: http://forums.pirate-zone.com/index.php?');
  //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
              WHERE
                  cat_id = " . mysql_real_escape_string($_GET['id']);
  
      $result = mysql_query($sql);
  
      if(!$result)
      {
  
          echo 'Error while selecting from database. Please try again later.';
      }
      else
      { $topic_cat=$row['cat_id'];
          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;div class="contain contentpadding"&gt;
  &lt;form action="" method="post"&gt;
  &lt;div style="margin: 10px 0 10px 120px"&gt;
  &lt;h3&gt;Topic Name (required)&lt;/h3&gt;
      &lt;br/&gt;
      &lt;div class="light contentpadding inputdiv"&gt;
          &lt;input type="text" name="topic_subject" size="50" /&gt;
      &lt;/div&gt;
      &lt;br/&gt;
      &lt;br/&gt;
  
  
  
      &lt;h3&gt;Topic Body (required)&lt;/h3&gt;
      &lt;/div&gt;
  &lt;br/&gt;
      &lt;div class="light contentpadding inputdiv"&gt;
          &lt;div class="cpadding"&gt;
  &lt;input type="button" class="bbbutton light" title="[color=][/color]" value="Color" /&gt;
  &lt;input type="button" class="bbbutton light" title="[size=11px][/size]" value="Size" /&gt;
  &lt;input type="button" class="bbbutton light" title="[b][/b]" value="Bold" /&gt;
  &lt;input type="button" class="bbbutton light" title="[i][/i]" value="Italic" /&gt;
  &lt;input type="button" class="bbbutton light" title="[u][/u]" value="Underline" /&gt;
  &lt;input type="button" class="bbbutton light" title="[img][/img]" value="Image" /&gt;
  &lt;input type="button" class="bbbutton light" title="[url=http://][/url]" value="URL" /&gt;
  &lt;input type="button" class="bbbutton light" title="[center][/center]" value="Center" /&gt;
  &lt;input type="button" class="bbbutton light" title="[quote=][/quote]" value="Quote" /&gt;
  &lt;input type="button" class="bbbutton light" title="[spoiler][/spoiler]" value="Spoiler" /&gt;
  &lt;input type="button" class="bbbutton light" title="  [youtube]http://www.youtube.com/watch?v=[/youtube]" value="YouTube Video" /&gt;
  &lt;/div&gt;
  &lt;div class="cpadding"&gt;
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/amazed.gif"  alt=":amazed" border="0" title=":amazed" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/amused.gif"  alt=":amused" border="0" title=":amused" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/blink.gif" alt=":blink" border="0" title=":blink" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/cheesy.gif" alt=":cheesy" border="0" title=":cheesy" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/confused.gif" alt=":confused" border="0" title=":confused" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/cool.gif" alt=":cool" border="0" title=":cool" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/cry.gif" alt=":cry" border="0" title=":cry" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/embarressed.gif" alt=":embarrassed" border="0" 
  
  title=":embarrassed" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/evil.gif" alt=":evil" border="0" title=":evil" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/huh.gif" alt=":huh" border="0" title=":huh" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/laugh.gif" alt=":laugh" border="0" title=":laugh" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/mad.gif" alt=":mad" border="0" title=":mad" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/notrust.gif" alt=":notrust" border="0" title=":notrust" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/noworry.gif" alt=":noworry" border="0" title=":noworry" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/nuts.gif" alt=":nuts" border="0" title=":nuts" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/oh.gif" alt=":oh" border="0" title=":oh" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/push.gif" alt=":push" border="0" title=":push" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/rolleyes.gif" alt=":rolleyes" border="0" title=":rolleyes" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/sad.gif" alt=":sad" border="0" title=":sad" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/sick.gif" alt=":sick" border="0" title=":sick" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/smile.gif" alt=":smile" border="0" title=":smile" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/suspicious.gif" alt=":suspicious" border="0" title=":suspicious" 
  
  /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/teeth.gif"   alt=":teeth" border="0" title=":teeth" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/tounge.gif" alt=":tounge" border="0" title=":tounge" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/unsure.gif" alt=":unsure" border="0" title=":unsure" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/wacko.gif" alt=":wacko" border="0" title=":wacko" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/weird.gif" alt=":weird" border="0" title=":weird" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/wondering.gif" alt=":wondering" border="0" title=":wondering" /&gt; 
  &lt;img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/worried.gif" alt=":worried" border="0" title=":worried" /&gt;
  &lt;br /&gt;
  
  &lt;/div&gt;
  &lt;br/&gt;           &lt;center&gt;&lt;textarea id="post_content" name="post_content"  cols="102" rows="13"&gt;&lt;/textarea&gt;&lt;/center&gt;
      &lt;/div&gt;
      &lt;br/&gt;
  
  
  &lt;/div&gt;
  &lt;div class="center"&gt;
          &lt;input type="submit" value="Post Topic" /&gt;
      &lt;/div&gt;
  &lt;/form&gt;
              &lt;/div&gt;';
          }
      }
  }
  else
  {
      //start the transaction
      $query  = "BEGIN WORK;";
      $result = mysql_query($query);
  
      if(!$result)
      {
  
          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)
                 VALUES('" .  mysql_real_escape_string($_POST['topic_subject']) . "',
                             NOW(),
                            '" . $topic_cat . "',
                             " . $_SESSION['user_id'] . "
                             )";
  
          $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)
                      VALUES
                          ('" . mysql_real_escape_string($_POST['post_content']) . "',
                                NOW(),
                                " . $topicid . ",
                                " . $_SESSION['user_id'] . "
                          )";
              $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;.';
              }
          }
      }
  }
  }
  
  
  ?&gt;   
  </code></pre>