brown2005 Posted July 24, 2013 Share Posted July 24, 2013 function CreateAction($selmgec,$domain,$member,$action){ global $db; $stmt = $db->prepare("INSERT INTO actions(actions_id,actions_selmgec,actions_type,actions_value,actions_member,actions_date,actions_action,actions_number)VALUES('',:field1,1,:field2,:field3,CURDATE(),:field4,0)"); $stmt->execute(array(':field1' => $selmgec,:field2' => $domain,':field3' => $member,':field4' => $action));} if(isset($_SESSION['member'])){ $stmt1 = $db->query("SELECT * FROM actions WHERE actions_selmgec='$_SESSION[selmgec]' AND actions_type='1' AND actions_value='$domain' AND actions_member='$_SESSION[member]' AND actions_action='4' OR actions_action='5' LIMIT 1"); if($stmt1->rowCount() > 0){ }else{ CreateAction($_SESSION['selmgec'],$domain,$_SESSION['member'],$action); } $stmt2 = $db->query("SELECT * FROM actions WHERE actions_selmgec='$_SESSION[selmgec]' AND actions_type='1' AND actions_value='$domain' AND actions_member='$_SESSION[member]' AND actions_action='2' OR actions_action='3' LIMIT 1"); if($stmt2->rowCount() > 0){ }else{ CreateAction($_SESSION['selmgec'],$domain,$_SESSION['member'],$action); } I have the above code, but it inserts the $stmt1 if twice generating two lots of the same data. Any help would be much appreciated Link to comment https://forums.phpfreaks.com/topic/280467-function-creates-two-entries/ Share on other sites More sharing options...
Psycho Posted July 24, 2013 Share Posted July 24, 2013 Aside from the fact that the code you posted has syntax errors and is invalid (see the array in the first execution statement), you state that $stmt1 is generating the duplicate data. But, $stmt1 is a SELECT query, $stmt (with no number) is the INSERT query and it only appears once. So, assuming your code doesn't have those syntax errors and the INSERT is only performed once in that function, then my guess is that the problem is not with the function, but that your script is calling the function twice. Link to comment https://forums.phpfreaks.com/topic/280467-function-creates-two-entries/#findComment-1441987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.