Alidad Posted September 7, 2008 Share Posted September 7, 2008 hi, does any one can me how i can write that code. Let say that person signed up and send data to the first database called "holding" database. When person recieved email conformation to verfiy to activity account, then it will transfer member information from first databse "holding" to the second database called activated. This part of code showing is transfering data from first called "holding" database to second database called "activated". $sql2 = "INSERT INTO activated (first_name, last_name, country, city, zip_code, user_name, email, password, b_month, b_day, b_year, gender, areyou) VALUES('".$first_name."', '".$last_name."', '".$country."', '".$city."', '".$zip_code."', '".$user_name."','".$email."', '".$password."', '".$b_month."','".$b_day."', '".$b_year."','".$gender."', '".$areyou."')"; $result2 = mysql_query($sql2, $ourdeafworld); My question is that how can i write code to transfer same data from first database to the "member" or fourth database called "member-2" at the same time when they transfer data to second database! please help thanks... AM Link to comment https://forums.phpfreaks.com/topic/123076-insert-data-into-two-different-database/ Share on other sites More sharing options...
nuttycoder Posted September 7, 2008 Share Posted September 7, 2008 you can get the id from a new query using mysql_insert_id() example $result = mysql_query("INSERT INTO table (one) VALUES ('$data')"; $getid = mysql_insert_id($result); //$getid now has the id from the previous query so you can use it for the next one $result2 = mysql_query("UPDATE table SET one = '$date' WHERE id = '$getid'"; Link to comment https://forums.phpfreaks.com/topic/123076-insert-data-into-two-different-database/#findComment-635585 Share on other sites More sharing options...
Alidad Posted September 7, 2008 Author Share Posted September 7, 2008 thanks so much for your response but i'm not quit get it right, please see full code that i copied from my php page called config.php, what they do is that once person recieved email conformation and click the link it will transfer data from first database called "temp_members" to the second database called "registered_members". how can i write that code to getid new query if i want also to trasnfer copy of data from first databse to the 3rd and fourth called "member" and "member-2"! please help me thanks. AM <?php require_once('Connections/config.php'); ?> <?php $anEmail_rstExists = "0"; if (isset($_POST['email'])) { $anEmail_rstExists = (get_magic_quotes_gpc()) ? $_POST['email'] : addslashes($_POST['email']); } mysql_select_db($database_ourdeafworld, $ourdeafworld); $query_rstExists = sprintf("SELECT * FROM registered_members WHERE email = %s ", $anEmail_rstExists); $rstExists = mysql_query($query_rstExists, $ourdeafworld) or die(mysql_error()); $row_rstExists = mysql_fetch_assoc($rstExists); $totalRows_rstExists = mysql_num_rows($rstExists); if ($totalRows_rstExists > 0) { header("Location: exists.php") ; } ?> <? // // confirmation.php // // // Known Errors: // - This does not check to determine if the name has previously been placed in the permanent database. // // // Passkey that got from link $passkey=$_GET['passkey']; // Retrieve data from table where row that match this passkey mysql_select_db($database_ourdeafworld, $ourdeafworld); $sql1 = "SELECT * FROM temp_members_db WHERE confirm_code ='".$passkey."'" ; $results = mysql_query($sql1, $ourdeafworld) ; $rows = mysql_fetch_assoc($results); $count = mysql_num_rows($results) ; if($results === FALSE){ echo "That is an illegal Confirmation code. If you believe this is an error, please contact the <a href='".$WEBMASTER."'>Webmaster</a>"; } else { // if found a passkey in our database, // retrieve data from table "temp_members_db" if($count > 0){ $first_name = $rows['first_name'] ; $last_name = $rows['last_name'] ; $country = $rows['country'] ; $city = $rows['city'] ; $zip_code = $rows['zip_code'] ; $user_name = $rows['user_name'] ; $email = $rows['email'] ; $password = $rows['password'] ; $b_month = $rows['b_month'] ; $b_day = $rows['b_day'] ; $b_year = $rows['b_year'] ; $gender = $rows['gender'] ; $areyou = $rows['areyou'] ; // Insert data that retrieves from "temp_members_db" // into table "registered_members" $sql2 = "INSERT INTO registered_members (first_name, last_name, country, city, zip_code, user_name, email, password, b_month, b_day, b_year, gender, areyou) VALUES('".$first_name."', '".$last_name."', '".$country."', '".$city."', '".$zip_code."', '".$user_name."','".$email."', '".$password."', '".$b_month."','".$b_day."', '".$b_year."','".$gender."', '".$areyou."')"; $result2 = mysql_query($sql2, $thegame); // if successfully moved data from table"temp_members_db" to table "registered_members" //displays message "Your account has been activated" and don't forget to delete confirmation code // from table "temp_members_db" if($result2 === FALSE ){ echo "Internal error; Failed to activate. Please re-select your activation link." ; } else { echo "Your account has been activated"; // Delete information of this user from table "temp_members_db" // that has this passkey $sql3 = "DELETE FROM temp_members_db WHERE confirm_code = '".$passkey."'" ; $result3 = mysql_query($sql3); header("Location: login.php") ; } } else { echo "That is an illegal Confirmation code. If you believe this is an error, please contact the <a href='".$WEBMASTER."'>Webmaster</a>"; } } mysql_free_result($results); mysql_free_result($rstExists); ?> Link to comment https://forums.phpfreaks.com/topic/123076-insert-data-into-two-different-database/#findComment-635589 Share on other sites More sharing options...
nuttycoder Posted September 7, 2008 Share Posted September 7, 2008 from looking at your code it would appear to copy the data from the first table as its adding the data to vars then using the vars for the insert table so it this not working? Link to comment https://forums.phpfreaks.com/topic/123076-insert-data-into-two-different-database/#findComment-635592 Share on other sites More sharing options...
DarkWater Posted September 7, 2008 Share Posted September 7, 2008 You could just add a "holding" column to a "users" table instead of having 2 tables... Link to comment https://forums.phpfreaks.com/topic/123076-insert-data-into-two-different-database/#findComment-635593 Share on other sites More sharing options...
nuttycoder Posted September 7, 2008 Share Posted September 7, 2008 I agree with DarkWater that would be simple and more efficient. Link to comment https://forums.phpfreaks.com/topic/123076-insert-data-into-two-different-database/#findComment-635594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.