cheechm Posted September 27, 2007 Share Posted September 27, 2007 Hi, I can't seem to make this script function. It runs however the database doesn't get updated: <?php // Lets open connections to MySQL database // ------------------------------------- $con1 = mysql_connect("*********************"); $db = mysql_select_db("**DB**", ($con1)) or die ("Couldn't select database."); $con2 = mysql_connect("*********************"); $db = mysql_select_db("**DB**", ($con2)) or die ("Couldn't select database."); // Lets get the data from the first site // ------------------------------------- $sql = "SELECT * FROM **TABLE**"; $query = mysql_query($sql, $con1); // If no data exists then there is no point executing the query // ------------------------------------- if (mysql_num_rows($query) == 0) { echo "Nothing to copy. Exiting now."; exit; } // Lets insert it into the other site // ------------------------------------- for ($i=0;$i<($result = mysql_fetch_assoc($query));$i++) {mysql_query("INSERT INTO probid_users (username, password, email, regdate) VALUES('username', 'password', 'email', 'joindate') ($con2)"); } mysql_close($con1); mysql_close($con2); ?> How can I make it so that they update the required tables..? Thanks in advanced. Quote Link to comment https://forums.phpfreaks.com/topic/70943-solved-updating-a-2-databases/ Share on other sites More sharing options...
Psycho Posted September 27, 2007 Share Posted September 27, 2007 Your for loop is not valid. You are doing a for loop where $i<mysql_fetch_assoc($query). mysql_fetch_assoc() does not return a number. Also once you assign the record to $result you need to reference those values correctly. Also, you put the connection parameter within the query string. Change this: <?php for ($i=0;$i<($result = mysql_fetch_assoc($query));$i++) {mysql_query("INSERT INTO probid_users (username, password, email, regdate) VALUES('username', 'password', 'email', 'joindate') ($con2)"); } ?> To this: f<?php while ($result = mysql_fetch_assoc($query)) { $sql = "INSERT INTO probid_users (username, password, email, regdate) VALUES ('".$result['username']."', '".$result['password']."', '".$result['email']."', '".$result['joindate']."')"; mysql_query($sql, $con2); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70943-solved-updating-a-2-databases/#findComment-356691 Share on other sites More sharing options...
cheechm Posted September 27, 2007 Author Share Posted September 27, 2007 Works perfect.. Thanks mate Quote Link to comment https://forums.phpfreaks.com/topic/70943-solved-updating-a-2-databases/#findComment-356714 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.