Lambneck Posted August 17, 2009 Share Posted August 17, 2009 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(); Link to comment https://forums.phpfreaks.com/topic/170625-solved-inserting-to-two-different-tables-simultaneously/ Share on other sites More sharing options...
DarkendSoul Posted August 17, 2009 Share Posted August 17, 2009 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 Link to comment https://forums.phpfreaks.com/topic/170625-solved-inserting-to-two-different-tables-simultaneously/#findComment-899937 Share on other sites More sharing options...
Lambneck Posted August 17, 2009 Author Share Posted August 17, 2009 Oh! I didnt think that could work Thanks! One more question about this. I want to get the id of the data in the first table to be inserted into a row in the table of the second insert. Does that make sense? (its been a long day) Link to comment https://forums.phpfreaks.com/topic/170625-solved-inserting-to-two-different-tables-simultaneously/#findComment-899942 Share on other sites More sharing options...
DarkendSoul Posted August 17, 2009 Share Posted August 17, 2009 http://ca.php.net/manual/en/function.mysql-insert-id.php Link to comment https://forums.phpfreaks.com/topic/170625-solved-inserting-to-two-different-tables-simultaneously/#findComment-899948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.