Jump to content

Function Creates Two Entries.


brown2005

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

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.

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.