pocobueno1388 Posted February 10, 2007 Share Posted February 10, 2007 Okay, what I am doing is populating the database with information. First I need to populate the first table. I am using this code: <?php include 'config.php'; $query = mysql_query("SELECT id FROM users"); while ($row = mysql_fetch_assoc($query)){ mysql_query("insert into land(ownedby,indistrict,whatisbuilt)values('$row[id]','Dragon Valley District','cave')")or die(mysql_error()); mysql_query("insert into land(ownedby,indistrict,whatisbuilt)values('$row[id]','Dragon Valley District','tank')")or die(mysql_error()); } ?> This code works just fine. After that I am trying to use this code to populate two other tables from the infromation I just inserted in the above code. <?php include 'config.php'; $query = mysql_query("SELECT id FROM users"); while ($row = mysql_fetch_assoc($query)){ $cquery=mysql_query("select acreID from land where ownedby='$row[id]' and whatisbuilt='cave'")or die(mysql_error()); $crow=mysql_fetch_assoc($cquery); $tquery=mysql_query("select acreID from land where ownedby='$row[id]' and whatisbuilt='tank'")or die(mysql_error()); $trow=mysql_fetch_assoc($cquery); mysql_query("insert into caves(cavename,cavelayout,indistrict,caveID,owner,mood)values('My Cave','No layout here!','Dragon Valley District','$crow[acreID]','$row[id]','10')")or die(mysql_error()); mysql_query("insert into tanks(tankname,tanklayout,indistrict,tankID,owner,mood)values('My Tank','No layout here!','Dragon Valley District','$trow[acreID]','$row[id]','10')")or die(mysql_error()); } echo "WORKED!"; ?> That code does not execute and returns NO errors...it just gives a blank screen. I was trying to get it to print out "WORKED!" if it executed, but it won't even print that..so it is obviously getting stuck somewhere. Do you guys see anything wrong with the code? I just don't understand why it is give me absolutely no errors. Thanks for all your help =D <b>EDIT:</b> I just changed the code. Now I am getting this error: Duplicate entry '1' for key 1 How can I get it to tell me what table it is talking about? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2007 Share Posted February 10, 2007 what is the primary key? are caveID and tankID set to primary unique keys? If they are, just make them autoincrement and you won't have to send a number for them. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.