soma
soma

Reputation: 71

run insert query after select query mysql in php

i am trying to insert into multi table after select query return 0 (not found raws) select query working and insert query never done when submite "displayid" and there is no any syntax error

code:

<?php
    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)
        }
    }
?>

Upvotes: 0

Views: 90

Answers (3)

Ahmad ghoneim
Ahmad ghoneim

Reputation: 927

AND stats='$ok'";

i can't see a variable with this name i think you mean AND stats='ok'";

Upvotes: 0

Maksym Semenykhin
Maksym Semenykhin

Reputation: 1945

you actually have one error

$conn->query($sqlfail) 

should be

$conn->query($sqlfail);  

Upvotes: 1

shubhamj
shubhamj

Reputation: 938

Use this code:

  $sqlfail = "INSERT INTO  fail(fname,lname,tname,funame,idnum,m_phone,reg_date)
VALUES ('".$pfname."','".$plname."','".$ptname."','".$pfuname."','".$pidnum."','".$pm_phone."','".$todaydate."')";

make similar changes for update command as well

Upvotes: 1

Related Questions