vendredi 23 novembre 2018

PHP MYSQL runs the query twice

When i run the following script. The row is inserted twice ( the query runs twice ) .

require_once $_SERVER['DOCUMENT_ROOT'].'/functions/sanitize.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/main/config.php';

$response    =   textsanitize($_POST['r']);
$ticket      =   idssanitize($_POST['t']);

$stmt = $condb->prepare("INSERT INTO ticket_reponses (ticket_id,user_id,time,response) VALUES (:ticket_id,:user_id,:time,:response)");
$stmt->execute(
array(
"ticket_id" => $ticket,
"user_id" => $_SESSION['user_id'],
"time" => time(),
"response" => $response
)
);
if($stmt->execute()){
   echo "SUCCESS";
}

When i remove if($stmt->execute()){echo "SUCCESSS";}. It runs in the right way. The row inserted once.

Why does if($stmt->execute()) execute the query again ? I thought that if($stmt->execute()) only returns TRUE || FALSE. I want to ensure that the query was executed successfully.

Aucun commentaire:

Enregistrer un commentaire