brown2005 Posted July 24, 2013 Share Posted July 24, 2013 (edited) 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 Edited July 24, 2013 by brown2005 Quote Link to comment 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. Quote Link to comment 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.