Reputation: 409
I'm working on a project that involved getting information from two different servers. What i plan on doing is having the user enter his or her username password and then have a php script fill in the rest of the fields below first name last name etc. I did some searching and found that some of the data i have is on two different tables within the server. Below is the coding I have so far.
<?php
$connect = mysql_connect("localhost","**************","**********") or die ("Couldn't Connect"); //host,username,password
mysql_select_db("*******") or die ("Could not find database");
$query = mysql_query("SELECT * FROM jos_users WHERE username='$username'");
?>
<html>
<form action="populate.php" method='post'>
<table>
<tr>
<td>VAE Username:</td>
<td><input type='text' name='username' value=''></td>
</tr>
<tr>
<td>VAE Password:</td>
<td><input type='password' name='password' value=''></td>
</tr>
</table>
<p><input type='submit' name='submit' value='Search & Populate!'></p>
</form>
//below is the information i want filled in from the MYSQL tables
<hr>
$query = mysql_query("SELECT * FROM jos_users WHERE username='$username'");
<form action="dafreg.php" method='post'>
<table>
<tr>
<td>Fristname:</td>
<td><input type='text' name='firstname' value='<?php echo $firstname; ?>'></td>
</tr>
<tr><td>Lastname:</td>
<td><input type='text' name='lastname' value='<?php echo $lastname; ?>'></td>
</tr>
<tr>
<td>Login:</td>
<td><input type='text' name='login' value='<?php echo $username; ?>'></td>
</tr>
<tr><td>Password:</td>
<td><input type='text' name='pass' value=''></td>
</tr>
<tr><td>Country:</td>
<td><input type='text' name='country' value=''></td>
</tr>
<tr><td>Pilot:</td>
<td><input type='checkbox' name='pilot' value=''></td>
</tr>
<tr><td>ATC:</td>
<td><input type='checkbox' name='atc' value=''></td>
</tr>
<tr><td>Email:</td>
<td><input type='text' name='email' value=''></td>
</tr>
</table>
<p><input type='submit' name='submit' value='Register'></p>
</form>
</form>
</html>
Upvotes: 0
Views: 794
Reputation:
Using 'JOIN' will be the best option for extracting the data multiple table...
SELECT tab1.*,tab2.*
FROM table1 tab1 JOIN table2 tab2
ON tab1.id=tab2.id
WHERE tab1.username=$username
Upvotes: 1
Reputation: 12998
If the two tables are on the same database you could left join the two tables based on a common factor (probably username in this case)
SELECT *
FROM jos_users
LEFT JOIN table_name2
ON jos_users.username=table_name2.username
WHERE jos_users.username = $username
Upvotes: 1