Can anyone see why maybe this set of select/insert statements always inserts a value of 0 instead of the selected site id in the first select statement? The variable $getid should hold the site id to be entered into the table ssx but its always entered at 0 and I get no php or mysql errors. Any help would be appreciated, thanks. $selectid="SELECT site_id FROM sites WHERE domain = \"$domain\""; $getid = mysql_query($selectid); echo mysql_error(); $hostsql2="INSERT INTO hostnames ( sid, hostname, ethernet_ip ) VALUES ( 'NULL', '$hostname', INET_NTOA('$ethernet_ip'))"; $hostresult2=mysql_query($hostsql2); echo mysql_error(); $details2="INSERT INTO details ( sid, os, home_dir, date, processor, memory, installs ) VALUES ( LAST_INSERT_ID(), '$os', '$home_dir', '$date', '$processor', '$memory', '$installs')"; $detailsresult2 = mysql_query($details2); $ssx2="INSERT INTO ssx ( id, sid, site_id ) VALUES ( 'NULL', LAST_INSERT_ID(), '$getid')"; $ssxresult2 = mysql_query($ssx2);