Jump to content

Recommended Posts

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{

Link to comment
https://forums.phpfreaks.com/topic/54931-multiple-table-insert-with-php-mysql/
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.