I just need to transfer a user's email address from one Table to the exact same field in another table without affecting the user's data and making sure the email is with the right user (as in in the row with the matching username)
What I want to do is check $username1 and $username2 and if they are the same I want it to copy $Email1 to $Email2 in the right row… So it would be like this
Username | Email
Chris | Chris@email.co
Joe | Joe@email.co
Monroe | Monroe@email.co
And it would insert the data into $username2 without affecting any other data on that table as well as be in that users row…
The reason why they all can’t be in one table is because Table1’s values are used in collecting xml data, parsing them and storing them in Table2….The only thing that xml doesn't supply is the Email, which is stored in Table1 upon registration…Given how often the xml feed changes, before the information is updated the script is configured to drop all information in Table 2. The xml feed I am using cannot be changed so it’s a problem I am trying to work around when dynamically displaying all the user data…
The Mysql structure is as follows:
DATABASE
TABLE1 {
Field1
Username1
Email1
}
TABLE2 {
Field2
Username2
Email2 (Empty)
}
I don’t normally ask for help but I’ve never had a problem that I couldn’t just fix... Since I cannot restructure my database I am out of ideas… Not only that but I have never had to query multiple tables before so I took my best whack at it to just toy around with it and see if I can do it…. I don’t know if this will help much but here is my “test” attempt…
<?
mysql_connect("localhost","username","password");
mysql_select_db("databaseName") or die("Unable to select database");
$result = mysql_query("select * from Table1");
$result2 = mysql_query("select * from Table2");
while($r=mysql_fetch_array($result))
{
$var1=$r["Field1"];
while($r2=mysql_fetch_array($result2))
{
$var2=$r2["Field2"];
if($var2==$var1) echo "WORKS GREAT!";
}
}
?>