Jump to content

Recommended Posts

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 by brown2005
Link to comment
https://forums.phpfreaks.com/topic/280467-function-creates-two-entries/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.