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 8777261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:14:21+00:00 2026-06-13T19:14:21+00:00

Tough question to ask, but basically I have a web form with a title,

  • 0

Tough question to ask, but basically I have a web form with a “title”, “message” and “image” boxes, they all work in uploading it to one table on mysql.

What I want to do is have another field in my form for WHERE i want it to post to, I have 2 pages and 2 tables at the moment. table Blog and table Blog_2
They both work if I change my insert.php to INSERT INTO Blog or Blog_2

But i want to be able to use the field and a $_POST[Blog]
function which is linked to a field in a form, it’s going to have a dropdown box to select either Blog or Blog_2

Below is my code. I’ve given it a go, but I cant seem to make it work.
I created a variable called $insert as you can see.

Maybe its just a syntax problem, but im not that PHP savvy.

<?php
$con = mysql_connect("xxx","xxx","xxx");
mysql_select_db("databse") or die(mysql_error());

$insert = '$_POST[Blog]';

mysql_query("INSERT INTO $insert
(Date, Title, Message, Image) 
VALUES(now(), '$_POST[Title]' , '$_POST[Message]' , '$_POST[Image]' ) ")
or die(mysql_error()); 

echo "1 record added";


mysql_close($con);
?>
  • 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-13T19:14:23+00:00Added an answer on June 13, 2026 at 7:14 pm

    Try as below

    $insert = mysql_real_escape_string($_POST['Blog']);
    
    mysql_query("INSERT INTO ".$insert."
    (Date, Title, Message, Image) 
    VALUES(now(), '$_POST[Title]' , '$_POST[Message]' , '$_POST[Image]' ) ")
    or die(mysql_error()); 
    

    Recommendations:

    1.Learn to prevent from MySQL Injections: Good Link

    2.Mysql extension is not recommended for writing new code. Instead, either the mysqli or PDO_MySQL extension should be used. More reading: PHP Manual

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry to have to ask yet another position:fixed related question, but reading through various
I'm not sure if this is possible, but I though I'd ask the question
I only ask this question because I have isolated it to pretty much three
I'm embarrassed to ask this question, but after 45 minutes of not finding a
A similar question was asked here , but the answers generally all seem to
So, this might be a very simple question but I'll ask anyway. And this
This is a bit of a tough question to ask. I am using asp.net
Sorry to double my earlier question, but I thought to ask specific data which
I carefully read the question 'Official way to ask jQuery wait for all images
This maybe a silly question, but I need confirmation and I have no one

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.