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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.