mysql查询执行多次

时间:2017-10-12 07:17:33

标签: php mysql mysqli

我有mysqli查询插入到数据库但是当我点击触发它时,它插入两次,插入一个哑数据,下面的真实数据是我的代码

<?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);
} {

}
?>

它工作正常,但插入两次,首先是一个愚蠢的数据,其次是真实的数据,现在已经看了一段时间,但仍然无法对错误进行罚款,请任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

先生,您可以尝试使用代码; 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); } `