SilverDragonTears Posted October 5, 2010 Share Posted October 5, 2010 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 https://forums.phpfreaks.com/topic/215240-data-isnt-being-entered-to-database/ Share on other sites More sharing options...
Pikachu2000 Posted October 5, 2010 Share Posted October 5, 2010 First, you need to go and immediately change your database credentials (username/password), since you've just posted them on the internet . . . Link to comment https://forums.phpfreaks.com/topic/215240-data-isnt-being-entered-to-database/#findComment-1119422 Share on other sites More sharing options...
Octo Posted October 5, 2010 Share Posted October 5, 2010 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 https://forums.phpfreaks.com/topic/215240-data-isnt-being-entered-to-database/#findComment-1119425 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.