• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 409
  • Last Modified:

Delete multiple rows from sql query

This code inserts multiple rows of data into a table:

if (!empty($_POST)) {
	foreach ($_POST['record'] as $data) {
		$insertSQL = sprintf(
		"INSERT INTO actualproduction (proddate, tankno, primeactual, tcactual, CHA, COR, REID, ROY, LEE, MANIS, DAN, MON, LES, MAR) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
			$data['prodDate'],
			$data['tankno'],
			$data['primeactual'],
			$data['tcactual'],
			(isset($data['LEE'])) ? $data['LEE'] : "No",
			(isset($data['COR'])) ? $data['COR'] : "No",
			(isset($data['REID'])) ? $data['REID'] : "No",
			(isset($data['ROY'])) ? $data['ROY'] : "No",
			(isset($data['LEE'])) ? $data['LEE'] : "No",
			(isset($data['MANIS'])) ? $data['MANIS'] : "No",
			(isset($data['DAN'])) ? $data['DAN'] : "No",
			(isset($data['MON'])) ? $data['MON'] : "No",
			(isset($data['LES'])) ? $data['LES'] : "No",
			(isset($data['MAR'])) ? $data['MAR'] : "No"
		);
		
		//echo $insertSQL;
		 mysql_select_db($database_pintura, $pintura);
  $Result1 = mysql_query($insertSQL, $pintura) or die(mysql_error());
	}                                            
}

Open in new window


At the same time, I would like to delete data from another table but not sure if this would work?

$deleteSQL = sprintf("DELETE FROM tankbasket WHERE tankno=%s",
                       $data['tankno']);

Open in new window

0
jonofat
Asked:
jonofat
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
hmmmmm....

if (!empty($_POST)) {
	foreach ($_POST['record'] as $data) {
		$insertSQL = sprintf(
		"INSERT INTO actualproduction (proddate, tankno, primeactual, tcactual, CHA, COR, REID, ROY, LEE, MANIS, DAN, MON, LES, MAR) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
			$data['prodDate'],
			$data['tankno'],
			$data['primeactual'],
			$data['tcactual'],
			(isset($data['LEE'])) ? $data['LEE'] : "No",
			(isset($data['COR'])) ? $data['COR'] : "No",
			(isset($data['REID'])) ? $data['REID'] : "No",
			(isset($data['ROY'])) ? $data['ROY'] : "No",
			(isset($data['LEE'])) ? $data['LEE'] : "No",
			(isset($data['MANIS'])) ? $data['MANIS'] : "No",
			(isset($data['DAN'])) ? $data['DAN'] : "No",
			(isset($data['MON'])) ? $data['MON'] : "No",
			(isset($data['LES'])) ? $data['LES'] : "No",
			(isset($data['MAR'])) ? $data['MAR'] : "No"
		);
		
		//echo $insertSQL;
		mysql_select_db($database_pintura, $pintura);
                $Result1 = mysql_query($insertSQL, $pintura) or die(mysql_error());

                $deleteSQL = sprintf("DELETE FROM tankbasket WHERE tankno=%s", $data['tankno']);
                mysql_query($deleteSQL , $pintura) or die(mysql_error());

                                  
	}                                            
}

Open in new window

0
 
jonofatAuthor Commented:
Schweet!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now