mysql INSERT INTO...SELECT with multiple tables
Posted: Mon Jan 09, 2006 12:03 pm
I'm trying to insert information into a single table from a bunch of separate tables. I have written the following code, but nothing is being written to the table. All of the source tables are full and should query, and no errors are being shown, but the table is coming up empty. Anyone see anything illegal in this query?
Any help would be appreciated.
Code: Select all
$sql="INSERT INTO seasonalresource (user,title,jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec,winc,wink,sprc,sprk,sumc,sumk,falc,falk,win,spr,sum,fal)"
."SELECT variables.username,"
."variables.title,"
.$username."_tmp_sun.jan,"
.$username."_tmp_sun.feb,"
.$username."_tmp_sun.mar,"
.$username."_tmp_sun.apr,"
.$username."_tmp_sun.may,"
.$username."_tmp_sun.jun,"
.$username."_tmp_sun.jul,"
.$username."_tmp_sun.aug,"
.$username."_tmp_sun.sep,"
.$username."_tmp_sun.oct,"
.$username."_tmp_sun.nov,"
.$username."_tmp_sun.dec,"
.$username."_tmp_wind.winWeibC,"
.$username."_tmp_wind.winWeibK,"
.$username."_tmp_wind.sprWeibC,"
.$username."_tmp_wind.sprWeibK,"
.$username."_tmp_wind.sumWeibC,"
.$username."_tmp_wind.sumWeibK,"
.$username."_tmp_wind.falWeibC,"
.$username."_tmp_wind.falWeibK,"
."NULL,NULL,NULL,NULL "
."FROM variables, "
.$username."_tmp_sun,"
.$username."_tmp_wind "
."WHERE variables.username='$username' "
."AND variables.title='$title' "
."AND ".$username."_tmp_sun.sunlatitude=$sunLat "
."AND ".$username."_tmp_sun.sunlongitude=$sunLon "
."AND ".$username."_tmp_wind.latitude=$windLat "
."AND ".$username."_tmp_wind.longitude=$windLon";
$result = mysql_query($sql) or die("couldn't write values to table: ".mysql_error());