doupao2277
2016-07-07 07:42
浏览 82
已采纳

在php中选择查询mysql后运行更新或插入查询

i have spend more than 24 hours trying to run update or insert query after select query but select query done and update or insert query never done when submite "displayid"

code##

if($_POST["displayid"]==TRUE) {

    $sqlid = "SELECT * FROM doc1 WHERE idnum ='$pidnum' AND stats='$ok'";
    $result = mysqli_query($conn, $sqlid);
    if (mysqli_num_rows($result) > 0) {
         $sqlup = "UPDATE doc1 SET  m_phone='$pmphone', seen='$dataseen' WHERE  idnum ='$pidnum'";
        mysqli_query($conn, $sqlup);
        $found=1;
    }
    else {
        $found=0;
        $sqlfail="INSERT INTO fail(fname,lname,tname,funame,idnum,m_phone,reg_date) VALUES('$pfname','$plname','$ptname','$pfuname','$pidnum','$pm_phone','$todaydate')";
        $conn->query($sqlfail);
    }

}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • duanbushi1479 2016-07-07 08:12
    最佳回答

    First of all you update query is wrong. for checking errors please add

    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    

    Updated code

    if ($_POST["displayid"] == TRUE) {
    
        $sqlid = "SELECT * FROM doc1 WHERE idnum ='$pidnum' AND stats='$ok'";
        $result = mysqli_query($conn, $sqlid);
        if (mysqli_num_rows($result) > 0) {
            $sqlup = "UPDATE doc1 SET  m_phone='$pm_phone', seen='$dataseen' WHERE  idnum ='$pidnum'";
            mysqli_query($conn, $sqlup);
            $found = 1;
        } else {
            $found = 0;
            $sqlfail = "INSERT INTO fail(fname,lname,tname,funame,idnum,m_phone,reg_date)
    VALUES ('$pfname','$plname','$ptname','$pfuname','$pidnum','$pm_phone','$todaydate')";
            $conn->query($sqlfail);
        }
    }
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题