Jump to content

[SOLVED] Inserting to two different tables simultaneously


Lambneck

Recommended Posts

Im trying to insert data into two seperate tables with in the same process.

 

So far I have the following being inserted into one table, but I want to have $tags inserted into another table(blog_tags). Can anyone help me?

if ( isset($_POST['submit']) ) {

require_once('load_data.php');

$connect = mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($database);

$title = mysql_real_escape_string($_POST['title']);
$post = mysql_real_escape_string($_POST['post']);
$category = mysql_real_escape_string($_POST['category']);
$tags = mysql_real_escape_string($_POST['tags']);
    $ip = $_SERVER['REMOTE_ADDR'];

   $insert = mysql_query("INSERT INTO $table (title, post, category, ip_address) VALUES ('$title', '$post', '$category', '$ip')") or die(mysql_error());
} 
header('Location: ../');
exit();

Is there a problem with just inserting again after? o.o;

 

if ( isset($_POST['submit']) ) {

 

 

 

require_once('load_data.php');

 

 

 

$connect = mysql_connect($db_host, $db_user, $db_pwd);

 

 

 

mysql_select_db($database);

 

 

 

 

 

 

$title = mysql_real_escape_string($_POST['title']);

 

 

 

$post = mysql_real_escape_string($_POST['post']);

 

 

 

$category = mysql_real_escape_string($_POST['category']);

 

 

 

$tags = mysql_real_escape_string($_POST['tags']);

    $ip = $_SERVER['REMOTE_ADDR'];

 

  $insert = mysql_query("INSERT INTO $table (title, post, category, ip_address) VALUES ('$title', '$post', '$category', '$ip')") or die(mysql_error());

 

  $insert_more = mysql_query("INSERT INTO blog_tags ...") or die(mysql_error());

 

}

header('Location: ../');

exit();[/php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.