joshgarrod Posted March 14, 2009 Share Posted March 14, 2009 Hi, I am trying to give the option to add data to more than one table if required, at the moment if the user selects a second category as apposed to selecting none it inserts the data only into one table: <?php if ($_POST['submit']) { $seccat = mysql_real_escape_string($_POST['seccat']); $category = mysql_real_escape_string($_POST['category']); if ($seccat == "None") { $title = mysql_real_escape_string($_POST['title']); $descr = mysql_real_escape_string($_POST['descr']); $stocknu = mysql_real_escape_string($_POST['stocknu']); $price = mysql_real_escape_string($_POST['price']); $category = mysql_real_escape_string($_POST['category']); $image = mysql_real_escape_string("$idir" . $_FILES['fupload']['name']); $SQL = "INSERT INTO $category"; $SQL .= " (title, descr, stocknu, price, category, image) VALUES "; $SQL .= " ('$title','$descr','$stocknu','$price', '$category', '$image') "; } else { $title = mysql_real_escape_string($_POST['title']); $descr = mysql_real_escape_string($_POST['descr']); $stocknu = mysql_real_escape_string($_POST['stocknu']); $price = mysql_real_escape_string($_POST['price']); $category = mysql_real_escape_string($_POST['category']); $image = mysql_real_escape_string("$idir" . $_FILES['fupload']['name']); $SQL = "INSERT INTO $category"; $SQL .= " (title, descr, stocknu, price, category, image) VALUES "; $SQL .= " ('$title','$descr','$stocknu','$price', '$category', '$image') "; $title = mysql_real_escape_string($_POST['title']); $descr = mysql_real_escape_string($_POST['descr']); $stocknu = mysql_real_escape_string($_POST['stocknu']); $price = mysql_real_escape_string($_POST['price']); $category = mysql_real_escape_string($_POST['category']); $image = mysql_real_escape_string("$idir" . $_FILES['fupload']['name']); $SQL = "INSERT INTO $seccat"; $SQL .= " (title, descr, stocknu, price, category, image) VALUES "; $SQL .= " ('$title','$descr','$stocknu','$price', '$category', '$image') "; } ?> Link to comment https://forums.phpfreaks.com/topic/149382-insert-data-into-multiple-table-from-one-form/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.