Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2010
    Posts
    1

    Red face Unanswered: Writing data to 2 Databases with 1 form

    I'm sure I have overlooked it somewhere but I am now aggravated and tired of reading.

    I have one form for registration. When someone registers I need the data of that form to populate 2 different databases.

    // create member
    $set = "firstname = '$firstname'," ;
    $set .= "lastname = '$lastname'," ;
    $set .= "email = '$email'," ;
    $set .= "paypal_email = '$paypal_email'," ;
    $set .= "username = '$username'," ;
    $set .= "password = '$password'," ;
    $set .= "show_oto = '1'," ;
    $set .= "referred_by = '$ref'," ;
    $set .= "date_joined = now()," ;
    $set .= "status = '$status'," ;
    $ip = $_SERVER['REMOTE_ADDR'] ;
    $set .= "ip = '$ip'," ;
    $set .= "jv_status = '0'," ;
    $set .= "mailing = '1'," ;

    if($rand == '')
    {
    $rand = md5(uniqid(rand(),1));
    }
    $set .= "randomstring = '$rand'" ;

    $mid = $db->insert_data_id("insert into ".$prefix."members set $set") ;

    this code inserts it into the first database.

    I then copied the code and altered it using the same variables using the structure from the second database and called it $set2:

    // create Downline member

    require "http://affilitize.info/a/dlb/config.php";

    $set2 = "firstname = '$firstname'," ;
    $set2 .= "lastname = '$lastname'," ;
    $set2 .= "Email = '$email'," ;
    $set2 .= "Username = '$username'," ;
    $set2 .= "Password = '$password'," ;
    $set2 .= "active = '$status'," ;
    $set2 .= "ref_by = '$ref'," ;
    $ip = $_SERVER['REMOTE_ADDR'] ;
    $set2 .= "IP = '$ip'," ;
    $set2 .= "Date = now()," ;
    $set2 .= "subscribed = '1'," ;

    if($rand == '')
    {
    $rand = md5(uniqid(rand(),1));
    }
    $set2 .= "randomstring = '$rand'" ;

    $mid = $db->insert_data_id("insert into users set $set2") ;
    Any help would be appreciated.

    What is the code to switch to the second database to finish submitting the form? http://www.dbforums.com/db_images_v3...lies/frown.gif

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    this is a PHP question rather than a MySQL question
    do you want it moving to the PHP forum?

    it depends on how your db's are set up
    if the database is on the same physical mysql server then you can use the same connection, and merely change the db mysql_select_db(<dbname>,.[<connection>])
    if the second db is on a different server you will need to open a new connection for that server

    if the db is on the same server I'm pretty certain you can access the other db using the fully qualified table names. it certainly can be doen when using the MySQL Query browser
    eg
    select myotherserver.tablename.columnname,thisserver.tabl ename.acolumnname ......
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •