please execute the index.php and see the magic
index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php include"connect.php"; $sqlsecond = "select * FROM secondtable order by name asc"; $resultsecond = mysql_query($sqlsecond,$linksecond); if (!$resultsecond) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while ($row = mysql_fetch_row($resultsecond)) { $words=$row[1]; ///check to first table if it exists $existqry="select * from firsttable where name='$words'"; $existqryresult=mysql_query($existqry,$linkfirst); $numrowsfirst=mysql_num_rows($existqryresult); echo $numrowsfirst."--".$words."<br>"; if($numrowsfirst!=1) { $qry="insert into firsttable(name)values('$words')"; $executionresult=mysql_query($qry,$linkfirst); } } ?> |
connect.php
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php $linkfirst = mysql_connect('localhost', 'root', ''); if (!$linkfirst) { die('Could not connect: ' . mysql_error()); } mysql_select_db('testlogin', $linkfirst) or die('Could not select database.'); $linksecond = mysql_connect('localhost', 'root', ''); if (!$linksecond) { die('Could not connect: ' . mysql_error()); } mysql_select_db('testlogin', $linksecond) or die('Could not select database.'); ?> |