How can I check before storing in mysql wether in array 1 of the variables already exist in my database. if $explode[$i] exist go to next. if not exist run the code below!
Here is my code in php:
$request_user_ids = $_GET['req'];
$explode = explode(',',$request_user_ids);
for ($i=0; $i<count($explode);$i++){
$result = mysql_query("
INSERT INTO fbinvite (memberid, fbsender, fbempfang, regdatum, fbreturn)
VALUES(NULL, '".$userid."', '".$explode[$i]."', NOW(), '0')");
How can I do that there are no double inserts.
First of all make the relevant set of attributes to be primary key or unique index of the table.
Then you have several options:
INSERT IGNORE INTO fbinvite ..., if you simply want to ignore duplicated data ORSELECT memberid FROM fbinvite WHERE some_attr1 = $explode[...] AND some_attr2 = $explode[...]; and continue appropriately:INSERT INTO fbinvite ...UPDATE fbinvide ... WHERE ...INSERT ... ON DUPLICATE KEY UPDATE ...