Jump to content

Queries not wanting to insert into the DB.


pocobueno1388

Recommended Posts

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.