Jump to content

[SOLVED] mysql update


php_b34st

Recommended Posts

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>';
}

Link to comment
https://forums.phpfreaks.com/topic/120427-solved-mysql-update/
Share on other sites

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.