If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Writing data to 2 Databases with 1 form

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-05-10, 18:05
affilitize.info affilitize.info is offline
Registered User
 
Join Date: Mar 2010
Posts: 1
Red face 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
Reply With Quote
  #2 (permalink)  
Old 03-06-10, 07:01
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,246
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On