Jump to content

Help inserting into multiple tables


ROCKINDANO
 Share

Recommended Posts

I am working on a asset project to insert, delete and view assets (items) that i owe. I am having trouble in the insert part.

 

i have four tables

 

department (DeptID, DeptName) DeptID is the primary key in this table.

 

assetcategory (AssetCatID, AssestCategory) AssetCatID is the primary key in this table.

 

asset (AssetID, AssetDescription, EmpID, AssetCatID, DeptID, Model, Maker, SerialNUm, DateAguired) AssetID is the primary key here.

 

Employee (EmpID, FirstName, LastName) EmpID is the key here.

 

and this is the code i have to insert using php.

		<?php 
			if(isset($_POST['submit'])){

				$FirstName = mysql_real_escape_string($_POST["FirstName"]);
				$LastName = mysql_real_escape_string($_POST["LastName"]);
				$DeptName = mysql_real_escape_string($_POST["DeptName"]);
				$AssetCategory = mysql_real_escape_string($_POST["AssetCategory"]);
				$Model = mysql_real_escape_string($_POST["Model"]);
				$Maker = mysql_real_escape_string($_POST["Maker"]);
				$SerialNum = mysql_real_escape_string($_POST["SerialNum"]);
				$DateAguired = mysql_real_escape_string($_POST["DateAguired"]);
				$AssetDescription = mysql_real_escape_string($_POST["AssetDescription"]);
				$AssetCatID = mysql_real_escape_string($_POST["AssetCatID"]);
				$AssetID = mysql_real_escape_string($_POST["AssetID"]);
				$EmpID = mysql_real_escape_string($_POST["EmpID"]);
				$DeptID = mysql_real_escape_string($_POST["DeptID"]);

				if(empty($FirstName) || empty($LastName) || empty($DeptName) || empty($AssetCategory) || empty($Model) || empty($Maker) || empty($SerialNum) || empty($DateAguired) || empty($AssetDescription))
				{
					print "Please feel in all fields";
				}
				else
				{
				///insert into the department table..........
				$query1= "INSERT INTO department VALUES (null,'{$DeptName}')";
				$result1 = mysql_query($query1) or die(mysql_error());
				$DeptID = mysql_insert_id();

				//insert into the assetcategory table
				$query2= "INSERT INTO assetcategory VALUES (null,'{$AssetCategory}')";
				$result2 = mysql_query($query2) or die(mysql_error());
				$AssetCatID = mysql_insert_id();

				//insert into the assets table
				$query3= "INSERT INTO assets VALUES (null,'{$AssetDescription}', '{$EmpID}','{$AssetCatID}','{$DeptID}','{$Model}','{$Maker}','{$SerialNum}','{$DateAguired}')";
				$result3 = mysql_query($query3) or die(mysql_error());
				$AssetCatID = mysql_insert_id();


				print $query1;

				}



			}
			else {
		?>

 

the page is displaying this error: "Column 'AssetCatID' cannot be null"

 

I would need help in inserting into all table required data. any help? hope i am making sense

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.