简体   繁体   中英

mysql query execute multiple time

I have mysqli query that insert to database but when i click trigger it, it insert twice,inserting a dumb data and the real data below is my code

<?php
$usernme = ($_POST['testify']);

$id = $_SESSION['XD'];

$ac = 1;
$ti = time();


$queryNewPlege = "INSERT INTO posts (text, timeline_id, active, time) 
      VALUES ('$usernme', '$id', '$ac', '$ti')";

if (mysqli_query($dbhandle, $queryNewPlege)) {

    $getLastInsertID = mysqli_insert_id($dbhandle);

    $upQuery = "UPDATE posts SET post_id =$getLastInsertID WHERE id=$getLastInsertID";
    mysqli_query($dbhandle, $upQuery);
} {

}
?>

it work fine but insert twice,first a dumb data and secondly the real data,been looking at it for some time now but still could not fined the error, please any help would be appreciated.

sir you may try following code; e $queryNewPlege = "INSERT INTO posts (text, timeline_id, active, time) VALUES ('$usernme', '$id', '$ac', '$ti')";'

$vars=mysqli_query($dbhandle,$queryNewPlege);  if(!$vars){

  }else{ $getLastInsertID = mysqli_insert_id($dbhandle);

  $upQuery = "UPDATE posts SET post_id =$getLastInsertID WHERE id=$getLastInsertID";
   mysqli_query($dbhandle, $upQuery); } `      

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM