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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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