php_b34st Posted August 19, 2008 Share Posted August 19, 2008 Hi, I have a table with over 1000 entries in it, I am using the following code to update the database on a weekly basis which works for any players that are currently in the database but it does not add any new players that are in the array because of the where clause however if i remove the where clause it just adds the data in again so i have 2 rows with almost identical fields, how can I update my database so that I can add new players aswell as players previously entered? foreach ($data as $listitem) { $listitem[1] = mysql_real_escape_string($listitem[1]); $query = "UPDATE playerlist SET code = '$listitem[0]', name = '$listitem[1]' , club = '$listitem[2]', price = '$listitem[3]', points = '$listitem[4]', position ='$position' WHERE code = $listitem[0]"; mysql_query($query) or die('Error, insert query failed'); echo $listitem[0] . ' ' . $listitem[1] . ' ' . $listitem[2] . ' ' . $listitem[3] . ' ' . $listitem[4].'</br>'; } Quote Link to comment https://forums.phpfreaks.com/topic/120427-solved-mysql-update/ Share on other sites More sharing options...
revraz Posted August 19, 2008 Share Posted August 19, 2008 INSERT with ON DUPLICATE KEY UPDATE option Quote Link to comment https://forums.phpfreaks.com/topic/120427-solved-mysql-update/#findComment-620519 Share on other sites More sharing options...
Lamez Posted August 19, 2008 Share Posted August 19, 2008 so are you asking on how to use a mysql_update query? <?php mysql_query("UPDATE `table` SET `name` = 'Lamez' WHERE `id` = '1'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/120427-solved-mysql-update/#findComment-620520 Share on other sites More sharing options...
php_b34st Posted August 19, 2008 Author Share Posted August 19, 2008 No lamez i know how to update just didnt know about the on duplicate key function thanks revraz I will figure out how to use that Quote Link to comment https://forums.phpfreaks.com/topic/120427-solved-mysql-update/#findComment-620526 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.