How to receive info from 2 tables from the same database in the same page?

I have 1 big form that will receive information from 2 different tables (table1 and table2) in the same database.

All info will be placed in the same form where you can save it all to a new table.

My issue is when some of the row in both table (table1 and table2) have the same name how do I call the info from the correct table. So fare I have:

The URL that will call the info looks like:


….info.php?id=320&folder=ras

The query:

if(!$_POST["submit"])
{
//INFO FORM TABLE 1
$query = mysql_query("select country, state, name, dob from table1 where id = '".$_GET["id"]."' ");
$row = mysql_fetch_row($query);
$country = $row[0];
$state = $row[1];
$name = $row[2];
$dob = $row[3];

//INFO FORM TABLE 2
$query = mysql_query("select country, state, name, dob from table2 where folder = '".$_GET["folder"]."' ");
$row = mysql_fetch_row($query);
$country = $row[0];
$state = $row[1];
$name = $row[2];
$dob = $row[3];

The vaiable on the website:

From table 1: //1 <?=$country?> //2 <?=$state?> //3 <?=$name?> //4 <?=$dob?>
From table 2: //1 <?=$country?> //2 <?=$state?> //3 <?=$name?> //4 <?=$dob?>

Im not sure how to do this, but I think that I need to change one of the query to something like:

$query2 = mysql_query("select country, state, name, dob from table2 where folder = '".$_GET["folder"]."' ");
$row = mysql_fetch_row($query2);
$country = $row[0];
$state = $row[1];
$name = $row[2];
$dob = $row[3];

But if I do that what variable should I use to call the info in table2?

<?=$2”country”?>

don’t work.

Please advice.

I found the selution my self:

//INFO FORM TABLE 2
$query = mysql_query(“select country, state, name, dob from table2 where folder = '”.$_GET[“folder”]."’ ");
$row = mysql_fetch_row($query);
$country2 = $row[0];
$state2 = $row[1];
$name2 = $row[2];
$dob2 = $row[3];

And in the html code use: <?=$country2?>

Keep in mind that there is no need to use variable names that match the column names in your database, it just makes it easier to figure out what information is being worked with. So any other variable name will do as long as you’re consistent where you use it. Just as you’ve chosen to suffix with a digit, you could also have chosen to include the table name, or anything else that helps. In fact using ‘id_country’ and ‘folder_country’ might make things clearer. Doesn’t matter, though, as long as they’re different if they need to be.

Also if you’re learning about PHP as I am, have a look at using PDO or mysqli libraries to access your database rather than the older mysql statements - apparently many hosting companies are starting to discontinue support for the older mysql statements and it might be easier to work through now with one of the newer access methods, rather than get used to the ‘old’ way.