How to detect non-ID users and remove them from Google sheet

1

I have the following code in a PHP code in my contactform.php which what it does is take the data and insert it in a google sheet.

if(!empty($_SESSION['nombre'])) {
$dataAgregar = array('gclid' => $_SESSION['gclid'],
'nombre' => $_SESSION['nombre'],
'email' => $_SESSION['email'],
'telefono' =>"'" .$_SESSION['phone'],
 'mensaje' => $_SESSION['mensaje'],
 'landing' =>  $landingP
 );
 $listFeed->insert($dataAgregar);
}
if(!empty($_SESSION['nombre2'])) {
  $dataAgregar2 = array('gclid' => $_SESSION['gclid2'],
'nombre' => $_SESSION['nombre2'],
 'email' => $_SESSION['email2'],
 'telefono' =>"'" .$_SESSION['phone2'],
 'mensaje' => $_SESSION['mensaje2'],
 'landing' =>  $landingP2
 );
 $listFeed->insert($dataAgregar2);
}    

What I want to do is that if there is no gclid do not insert it in the google sheet, I thought about making the following code to perform this function.

if(empty($_SESSION['gclid'])){}
if(empty($_SESSION['gclid2'])){}/*Es porque tengo dos gclid*/
if(!empty($_SESSION['nombre'])) {
$dataAgregar = array('gclid' => $_SESSION['gclid'],
'nombre' => $_SESSION['nombre'],
'email' => $_SESSION['email'],
'telefono' =>"'" .$_SESSION['phone'],
 'mensaje' => $_SESSION['mensaje'],
 'landing' =>  $landingP
 );
 $listFeed->insert($dataAgregar);
}
if(!empty($_SESSION['nombre2'])) {
  $dataAgregar2 = array('gclid' => $_SESSION['gclid2'],
'nombre' => $_SESSION['nombre2'],
 'email' => $_SESSION['email2'],
 'telefono' =>"'" .$_SESSION['phone2'],
 'mensaje' => $_SESSION['mensaje2'],
 'landing' =>  $landingP2
 );
 $listFeed->insert($dataAgregar2);
}

Would the code be fine to do what I want to do?

    
asked by AitorUdabe 13.10.2016 в 10:36
source

1 answer

1

You could check the two variables at once if they are empty:

if (!empty($_SESSION['gclid'] && !empty($_SESSION['nombre'])) { 
// Tú código 
}
    
answered by 13.10.2016 / 11:10
source