Jump to content

[SOLVED] inserting into two related tables


ROCKINDANO

Recommended Posts

Hello everyone,

 

I am working on a project that requires updating two tables using a form.

the two tables are related tables that need to be updated  when submitting the form. my two tables are:

 

fulltime (department, pay, jobnum, dateclose, job_id)

departments (dept_id, job_id, summary, description, conditions, ex, ed)

 

i have tried updating both tables using two querys but only the fulltime table get updated and nothing gets inserted into the department tables.

 

this is my code:

 

					$department=$_POST["department"];
					$pay=$_POST["pay"];
					$jobnum=$_POST["jobnum"];
					$dateclose=$_POST["dateclose"];
					$job_id=$_POST["job_id"];

					$dept_id=$_POST["dept_id"];
					$summary=$_POST["summary"];
					$description=$_POST["description"];
					$conditions=$_POST["conditions"];
					$ex=$_POST["ex"];
					$ed=$_POST["ed"];

					if(!isset($department) || empty($pay))
					die ("<p>You can't leave the title field blanck.</p>");
					if(!isset($department) || empty($pay))
					die ("<p>You can't leave the story field field blanck.</p>");

				//INSERTS INTO PROPER TABLES.
				$query= "INSERT INTO fulltime VALUES ('{$department}','{$pay}','{$jobnum}','{$dateclose}',NULL)";
				$result = mysql_query($query) or die(mysql_error());
				print $query;

				//insert into the department table
				$query = "insert into departments values(null,'{$job_id}','{$summary}','{$description}','{$conditions}','{$ex}','{$ed}')";
				$result = mysql_query($query2) or die(mysql_error());
				print $query;

 

any help please what am i doing wrong?

 

THanks in advance.

 

this is the echo

 

INSERT INTO fulltime VALUES (' title','pay','jobq','date',null)insert into departments values(null,'','summary','equipment','conditions','example','education')

 

the table structures are

 

fulltime (department, pay, jobnum, dateclose, job_id)

job_id is the primary key in this table

 

second table

departments (dept_id, job_id, summary, description, conditions, ex, ed)

dept_id is the primary key in this table

job_id is the foreign key from fulltime

 

another thing i notice is that when i fill the form out and click submit, it inserts all info to both tables but the job_id doesnt go into the second table. i found out this by checking the tables on phpmyadmin

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.