Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8639365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:58:59+00:00 2026-06-12T10:58:59+00:00

How do I make it so that the topic_cat= the current category, for example

  • 0

How do I make it so that the topic_cat= the current category, for example http://prntscr.com/h08ae 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:

 <?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 <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
            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 '      
<div class="contain contentpadding">
<form action="" method="post">
<div style="margin: 10px 0 10px 120px">
<h3>Topic Name (required)</h3>
    <br/>
    <div class="light contentpadding inputdiv">
        <input type="text" name="topic_subject" size="50" />
    </div>
    <br/>
    <br/>



    <h3>Topic Body (required)</h3>
    </div>
<br/>
    <div class="light contentpadding inputdiv">
        <div class="cpadding">
<input type="button" class="bbbutton light" title="[color=][/color]" value="Color" />
<input type="button" class="bbbutton light" title="[size=11px][/size]" value="Size" />
<input type="button" class="bbbutton light" title="[b][/b]" value="Bold" />
<input type="button" class="bbbutton light" title="[i][/i]" value="Italic" />
<input type="button" class="bbbutton light" title="[u][/u]" value="Underline" />
<input type="button" class="bbbutton light" title="[img][/img]" value="Image" />
<input type="button" class="bbbutton light" title="[url=http://][/url]" value="URL" />
<input type="button" class="bbbutton light" title="[center][/center]" value="Center" />
<input type="button" class="bbbutton light" title="[quote=][/quote]" value="Quote" />
<input type="button" class="bbbutton light" title="[spoiler][/spoiler]" value="Spoiler" />
<input type="button" class="bbbutton light" title="  [youtube]http://www.youtube.com/watch?v=[/youtube]" value="YouTube Video" />
</div>
<div class="cpadding">
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/amazed.gif"  alt=":amazed" border="0" title=":amazed" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/amused.gif"  alt=":amused" border="0" title=":amused" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/blink.gif" alt=":blink" border="0" title=":blink" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/cheesy.gif" alt=":cheesy" border="0" title=":cheesy" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/confused.gif" alt=":confused" border="0" title=":confused" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/cool.gif" alt=":cool" border="0" title=":cool" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/cry.gif" alt=":cry" border="0" title=":cry" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/embarressed.gif" alt=":embarrassed" border="0" 

title=":embarrassed" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/evil.gif" alt=":evil" border="0" title=":evil" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/huh.gif" alt=":huh" border="0" title=":huh" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/laugh.gif" alt=":laugh" border="0" title=":laugh" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/mad.gif" alt=":mad" border="0" title=":mad" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/notrust.gif" alt=":notrust" border="0" title=":notrust" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/noworry.gif" alt=":noworry" border="0" title=":noworry" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/nuts.gif" alt=":nuts" border="0" title=":nuts" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/oh.gif" alt=":oh" border="0" title=":oh" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/push.gif" alt=":push" border="0" title=":push" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/rolleyes.gif" alt=":rolleyes" border="0" title=":rolleyes" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/sad.gif" alt=":sad" border="0" title=":sad" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/sick.gif" alt=":sick" border="0" title=":sick" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/smile.gif" alt=":smile" border="0" title=":smile" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/suspicious.gif" alt=":suspicious" border="0" title=":suspicious" 

/> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/teeth.gif"   alt=":teeth" border="0" title=":teeth" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/tounge.gif" alt=":tounge" border="0" title=":tounge" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/unsure.gif" alt=":unsure" border="0" title=":unsure" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/wacko.gif" alt=":wacko" border="0" title=":wacko" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/weird.gif" alt=":weird" border="0" title=":weird" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/wondering.gif" alt=":wondering" border="0" title=":wondering" /> 
<img class="bbemoticon" src="http://www.soul-boards.com/images/smilies/worried.gif" alt=":worried" border="0" title=":worried" />
<br />

</div>
<br/>           <center><textarea id="post_content" name="post_content"  cols="102" rows="13"></textarea></center>
    </div>
    <br/>


</div>
<div class="center">
        <input type="submit" value="Post Topic" />
    </div>
</form>
            </div>';
        }
    }
}
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.<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)
                    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.<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>.';
            }
        }
    }
}
}


?>   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:59:01+00:00Added an answer on June 12, 2026 at 10:59 am

    Never use this approach.Do not echo before or after the header("location")

      header('Location: http://forums.pirate-zone.com/index.php?');
        //the user is not signed in
        echo 'Sorry, you have to be <a href="/forum/signin.php">signed in</a> to create a  topic.';
        }
    

    and You haven’t fetched the array returned by mysql_query() Use this

        while($row = mysql_fetch_assoc($result))
     {
     $topic_cat=$row['cat_id'];
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I'm using Windows, just to make that clear. I am using
im trying to make input that automaticaly change to decimel while typing number but
I want to make a program that monitors the other programs running on Windows.
sorry for that question, but i've searched about that topic, and it's not really
I want to use a command to make a crontab that plays an alarm
I know that this topic has been asked several times before but none of
ok, I know that this topic has been addressed several times on here, but
Before I begin I want to make it clear that I don't want the
Short question: I'm trying to make that in a given page (uses tabs) back
I have a WordPress blog and I'm trying to make that when a user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.