In my wordpress project i want to run a mysql query in thank you page when user is redirected to it only once a time. But when user refresh it, it should not run. I created a session variable and did the below way. But it did not work. Can somebody help me.
session_start();
$_SESSION['countval']=0;
if($_SESSION['countval']==0){
$wpdb->insert('wp_user_points',
array('user_id' =>$current_user->ID ,
'order_id'=>$order_id,
'product_sku' =>$new_sku,
'pv'=>$points,
'added_on'=>date("Y-m-d H:i:s"),
'payment_method'=>$order->payment_method_title,
'payment_statues'=>'pending'
)
);
$_SESSION['countval']++;
}
you seems to be resetting your counter every time. instead of having this line of code
$_SESSION['countval']=0;
make sure you only set it one time by testing to see if its already set.
Because you set
$_SESSION['countval']=0;
in first line.Use this code: