close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Trying to do a multiple insert into 2 tables

Thread began 12/22/2020 4:27 am by Sweens | Last modified 12/22/2020 8:34 am by Ray Borduin | 15 views | 2 replies |

Sweens

Trying to do a multiple insert into 2 tables

Hi Ray

I'm trying to insert new users into two tables, users and site_members.

I want the newly created users.UserID from the first insert behaviour to be inserted into the site_members.sm_user_id field - but it doesn't appear in the list of available fields.

(The insert single record behaviour creates a session variable for the field, so I can do it for adding records individually).

Any directions much appreciated.

Cheers
Chris

Sign in to reply to this post

Ray BorduinWebAssist

If I'm understanding you correctly, this will have to be hand coded.

I see your queryobj and rsobj includes are too low on the page... move those up.

Then you can manually add code to the first multiple insert code to make it do two inserts like:

php:
<?php

if (isset($_POST["btnAdduser"]) || isset($_POST["btnAdduser_x"])) {  // updated manually
  
$MultipleInsertConnection $connEGM_i;
  
$MultipleInsertTable "users";
  
$MultipleInsertRedirect "2-users_MultiInsert.php?ins=success";
  
$MultipleInsertCheck "fmEmail";
  
$MultipleInsertIdentifier 'wamultiinsert_1';
  for (
$mi=0$mi<sizeof($_POST[$MultipleInsertIdentifier]); $mi++) {
    
$MultipleInsertCount $_POST[$MultipleInsertIdentifier][$mi];
    if ((
$MultipleInsertCheck == "" || (isset($_POST[$MultipleInsertCheck.'_'.$MultipleInsertCount]) && $_POST[$MultipleInsertCheck.'_'.$MultipleInsertCount]!=""))) {
      
$InsertQuery = new WA_MySQLi_Query($MultipleInsertConnection);
      
$InsertQuery->Action "insert";
      
$InsertQuery->Table $MultipleInsertTable;
      
$InsertQuery->bindColumn("UserEmail""s""".((isset($_POST["fmEmail"."_".$MultipleInsertCount]))?$_POST["fmEmail"."_".$MultipleInsertCount]:"")  ."""WA_IGNORE");
      
$InsertQuery->bindColumn("UserPassword""s""".((isset($_POST["pwd"."_".$MultipleInsertCount]))?$_POST["pwd"."_".$MultipleInsertCount]:"")  ."""WA_IGNORE");
      
$InsertQuery->bindColumn("UserFirstName""s""".((isset($_POST["firstname"."_".$MultipleInsertCount]))?$_POST["firstname"."_".$MultipleInsertCount]:"")  ."""WA_IGNORE");
      
$InsertQuery->bindColumn("UserLastName""s""".((isset($_POST["surname"."_".$MultipleInsertCount]))?$_POST["surname"."_".$MultipleInsertCount]:"")  ."""WA_IGNORE");
      
$InsertQuery->bindColumn("UserEmailVerified""i""1""WA_IGNORE");
      
$InsertQuery->execute();
        
        
      
$InsertQuery2 = new WA_MySQLi_Query($MultipleInsertConnection);
      
$InsertQuery2->Action "insert";
      
$InsertQuery2->Table "site_members";
      
$InsertQuery2->bindColumn("sm_site_id""i""".$InsertQuery->InsertID  ."""WA_DEFAULT");
      
$InsertQuery2->bindColumn("sm_site_user""i""".$_SESSION['SiteID']  ."""WA_DEFAULT");
      
$InsertQuery2->bindColumn("sm_userlevel""i""2""WA_DEFAULT");
      
$InsertQuery2->execute();
        
    }
  }
  if (
$MultipleInsertRedirect) {
    if (
function_exists("rel2abs")) $MultipleInsertRedirect rel2abs($MultipleInsertRedirect,dirname(__FILE__));
    
header("location: " $MultipleInsertRedirect);
  }
}
?>



Then delete the second multiple insert entirely.

Sign in to reply to this post
Did this help? Tips are appreciated...

Sweens

Hi Ray

Thank you so much - modified a field name and it works a treat!

Just need to add validation to the email address now.

Many thanks, once more, and best wishes for Christmas and beyond.

Cheers

Chris

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...