chillininvt Posted June 10, 2007 Share Posted June 10, 2007 Ok I am having and issue getting this code working. It seems rather simple but I cannot figure out why only one sql statement is exectuing and the insert statements the other 2 are not exectuting and updating the other 2 tables. I need to do this. I need to update one table, then from that I need to retrieve the mysql_insert_id or just get the id of the last record in the tabe. There is an auto increment column that gets assigned a unique id each time a record is inserted. I need this id number then I need it to place data into 2 other tables that will use this value as a reference. here is the code. if( isset($_POST['btnSubmit']) ) { $department_id = $_GET['department_id']; if( $department_id == "" ) { // ADD NEW mysql_query("INSERT INTO CityHallDepartment (department_name) VALUES ('" . $_POST['department_name'] . "')"); echo "This is the department id".$departmentid.""; $departmentname = $_POST['department_name']; if($departmentname != NULL){ $departmentid = mysql_insert_id(); mysql_query("INSERT INTO PageGeneric (pid, bannerid, title, content, metadesc, layoutID) VALUES ('0', '$departmentname', 'Comming Soon', '$departmentname', '3')"); echo"The script executed into while loop"; $page = "generalpage.php?page=".$departmentid.""; mysql_query("INSERT INTO PageLocations (parentID, location, title, display, displayNavCMS, departmentID) VALUES ('0', '$page', '$departmentname', '1', '1', '0', $departmentid)"); }else{ Quote Link to comment https://forums.phpfreaks.com/topic/54931-multiple-table-insert-with-php-mysql/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.