ROCKINDANO Posted January 14, 2009 Share Posted January 14, 2009 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 https://forums.phpfreaks.com/topic/140815-solved-inserting-into-two-related-tables/ Share on other sites More sharing options...
revraz Posted January 14, 2009 Share Posted January 14, 2009 Your second query variable is wrong, it should be $query2= Right now its just $query= Link to comment https://forums.phpfreaks.com/topic/140815-solved-inserting-into-two-related-tables/#findComment-737017 Share on other sites More sharing options...
ROCKINDANO Posted January 14, 2009 Author Share Posted January 14, 2009 but it still doesn't update the second table. Link to comment https://forums.phpfreaks.com/topic/140815-solved-inserting-into-two-related-tables/#findComment-737019 Share on other sites More sharing options...
revraz Posted January 14, 2009 Share Posted January 14, 2009 echo $query and $query2 and check the strings. Link to comment https://forums.phpfreaks.com/topic/140815-solved-inserting-into-two-related-tables/#findComment-737022 Share on other sites More sharing options...
ROCKINDANO Posted January 14, 2009 Author Share Posted January 14, 2009 i did and still nothing. it echos out the info that i'm trying to submit but nothing when viewing the second table. Link to comment https://forums.phpfreaks.com/topic/140815-solved-inserting-into-two-related-tables/#findComment-737037 Share on other sites More sharing options...
revraz Posted January 14, 2009 Share Posted January 14, 2009 Post the echo's and both table structures. Link to comment https://forums.phpfreaks.com/topic/140815-solved-inserting-into-two-related-tables/#findComment-737040 Share on other sites More sharing options...
ROCKINDANO Posted January 14, 2009 Author Share Posted January 14, 2009 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 https://forums.phpfreaks.com/topic/140815-solved-inserting-into-two-related-tables/#findComment-737049 Share on other sites More sharing options...
ROCKINDANO Posted January 14, 2009 Author Share Posted January 14, 2009 for some reason it does not get the job_id from the fulltime table Link to comment https://forums.phpfreaks.com/topic/140815-solved-inserting-into-two-related-tables/#findComment-737065 Share on other sites More sharing options...
ROCKINDANO Posted January 14, 2009 Author Share Posted January 14, 2009 why wouldn't it get the job_id from the fulltime table or pass it to the second query? Link to comment https://forums.phpfreaks.com/topic/140815-solved-inserting-into-two-related-tables/#findComment-737085 Share on other sites More sharing options...
fenway Posted January 14, 2009 Share Posted January 14, 2009 Let's see both queries echo'd please. Link to comment https://forums.phpfreaks.com/topic/140815-solved-inserting-into-two-related-tables/#findComment-737171 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.