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

  • Home
  • SEARCH
  • 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 8689787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:44:34+00:00 2026-06-12T23:44:34+00:00

PHP newbie here I have a mysql table called topics, and i’m pulling information

  • 0

PHP newbie here

I have a mysql table called “topics”, and i’m pulling information from the table for a page based on a result from a form (in the URL through GET)

If the URL doesn’t exist, i’d like to be able for the table to create a new entry with the topic name from the URL filled in

$topic_name would be what i’d be putting in the new topicname field

My code so far:

            $topic_name = strtolower(mysql_real_escape_string($_GET['t']));

//look for info
$topic_info = mysql_query("SELECT * FROM topics WHERE topicname = '$topic_name' LIMIT 1");

if (mysql_numrows($topic_info)<=0) {
//insert record
$SQL='insert into topics (topicname) values ("'.$topic_name.'")';
mysql_query($SQL);
$t_desc='NEW TOPIC : '.$topic_name;
} 
else {
//do as normal (without unnessecary loop)
$g=mysql_fetch_array($topic_info);

$t_desc = $g['desc'];               
}    

EDIT: Sorry, I don’t think i explained well, the result is from a GET from a form, so url.com/topic?=BLAH

blah would be the name of the field i’d want to create if it doesn’t exist.

The table has an Auto incrementing ‘ID’ (primary key)

  • 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-12T23:44:35+00:00Added an answer on June 12, 2026 at 11:44 pm

    If i understand you correct :

    $topic_name = (isset($_GET['t'])) ? strtolower(mysql_real_escape_string($_GET['t'])) : '';
    
    //look for info
    $topic_info = mysql_query("SELECT * FROM topics WHERE topicname = '$topic_name' LIMIT 1");
    
    if (mysql_num_rows($topic_info)<=0) {
        //insert record
        //UPDATE
        //$SQL='insert into topics (topicname) values ("'.$topic_name.'")';
        $SQL='insert into topics (topicname, `desc`) values '.
               '("'.$topic_name.'", "NEW TOPIC DESC")';
        mysql_query($SQL);
        $t_desc='NEW TOPIC : '.$topic_name;
    } else {
        //do as normal (without unnessecary loop)
        $g=mysql_fetch_array($topic_info);
        $t_desc = $g['desc'];               
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

a bit of a PHP / MySQL newbie here... I've been building a PHP-based
Mysql , php newbie here. Please be nice . I have a list of
Im sure this is simple but newbie here. I have 5 URLS cards.php&type=one cards.php&type=two
I am a newbie in MySQL and PHP. I have a HTML form where
Ok so i have a database table called requests with this structure mysql> desc
php newbie here..I need some PHP help ideas/examples on how to import data from
I'm newbie in php mysql and google maps v3. I have a problems in
A really php newbie here, sorry if the question is too simple. I’m following
I'm a newbie to sql and am trying to follow this example here: http://net.tutsplus.com/tutorials/php/a-better-login-system/
I'm a PHP newbie working a some scripts to display some news articles from

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.