Jump to content

insert data into multiple table from one form


joshgarrod

Recommended Posts

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') ";
	}
?>

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.