0

Warning received:

Warning: mysqli::query(): Empty query in C:\wamp\www\otp-task\welcome.php on line 62

My database connection is here:

function insertDB($email, $OTP , $phonenumber )
{
    $servername = "localhost";
    $username = "root";
    $password = "";
    $db  = "dbotp";

    $conn = new mysqli($servername, $username, $password, $db);

    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    // insert to db and close the connection, default time attribute is 60 mins
    // the table name is onetime and will hold the otp and phonenum and email

    $res = mysqli_query($conn, "INSERT INTO onetime (otpnum,email,phoneNum,action) VALUES ('$OTP' , '$email' , '$phonenumber','success')");


    // $res = "INSERT INTO onetime (otpnum,email,phoneNum,action) VALUES ('$OTP' , '$email' , '$phonenumber', 'success')";


    if ($conn->query($res) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $res . "<br>" . $conn->error;
    }

    $conn->close();
}
Panda
  • 6,955
  • 6
  • 40
  • 55
roxor
  • 11
  • 5
  • Execute query two times produce that error!! comment this line `\\if ($conn->query($res) === TRUE)` and use `if($res)` – Saty May 10 '16 at 13:00

1 Answers1

0

The following two is just a different format for the same thing:

$conn->query(...)

and

mysqli_query($conn, ...)

Once you executed one of them, use the return value of it instead of re-executing the query:

$res =  $conn->query(...)
if ($res) {
    // ...
}

Please also read about prepared statements: http://php.net/manual/en/mysqli-stmt.prepare.php

fejese
  • 4,601
  • 4
  • 29
  • 36