ismail ahmed ismail ahmed - 4 months ago 24
MySQL Question

run update or insert query after select query mysql in php

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

}

Answer

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);
    }
}
Comments