Jump to content

Data isn't being entered to database


SilverDragonTears

Recommended Posts

Here is my code for entering data into the database

<?php
ini_set("display_errors",false);
$link = mysql_connect('mysql5.000webhost.com', 'a9634375_dragons', 'samantha8',true); if (!$link) {      die('Could not connect: ' . mysql_error()); }
mysql_select_db("a9634375_dragons") or die(mysql_error());
$ids=$_GET['checkboxes'];

$user = $_GET['user'];
$young = unserialize(file_get_contents('http://www.dragcave.net/api/samantha8/serialize/user/'.$user.''));

foreach ($young['dragons'] as $key => $value) {
$querya = "DELETE FROM hatch WHERE code='$key'";
$queryb = "DELETE FROM er WHERE code='$key'";
$queryc = "DELETE FROM eggs WHERE code='$key'";
mysql_query($querya);
mysql_query($queryb);
mysql_query($queryc);
}
echo '<br>Dragons updated.<br>';
echo 'Dragons now entered:<br>';
foreach ($ids as $hey) {
echo '<br><a href="http://www.dragcave.net/view/'.$hey.'" target="frame1"><img src="http://www.dragcave.net/image/'.$hey.'.gif" border="0"></a> ';

$data = unserialize(file_get_contents('http://www.dragcave.net/api/samantha8/serialize/view/'.$hey.''));
$hrsleft = $data['dragons'][$hey]['hoursleft'];
$hatch = $data['dragons'][$hey]['hatch'];

if ($hrsleft < 96) {
$query3 = "INSERT INTO er(code) VALUES('$hey')";
mysql_query($query3);
echo 'Dragon has been entered into the ER.<br>';
}
else
{
if  (! $hatch) {
$query4 = "INSERT INTO eggs(code) VALUES('$hey')";
mysql_query($query4);
echo 'Egg has been entered into the Nest.<br>';
}
else
{
$query2 = "INSERT INTO hatch(code) VALUES('$hey')";
mysql_query($query2);
echo 'Hatchling has been entered into the Nursery.<br>';
}
}
}

?>

 

My table is simply set up with three fields

er

egg

hatch

 

What am I doing wrong?

Thank you in advance!

Link to comment
Share on other sites

Your query statements are wrong.

 

$queryc = "DELETE FROM eggs WHERE code='$key'";

 

This is not correct, it should be "DELETE FROM table_name WHERE some_column = some_value"

 

You have "DELETE FROM some_column WHERE code = some_value"

 

DELETE is for deleting entire records at once, not individual entries in fields. Also, what is 'code'? And why must it equal the $key rather than the $value?

 

Similar issue with these:

 

$query2 = "INSERT INTO hatch(code) VALUES('$hey')";

 

INSERT is for entering entirely new records (rows) into a table not updating fields. For this you should use UPDATE. You INSERT INTO [tablename] and not a column name.

 

Lastly - you have display errors off. If you had it on then MYSQL would probably tell you didn't have any tables called 'er', 'egg' or 'hatch' which would help you a lot.

 

Ninja'd on the DB details by above.

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.