Warning: mysqli_query(): Empty query in /var/sites

2019-06-15 00:18发布

问题:

I am new to PHP and SQL.

Here is the code I have ( I will hash my logins when its working

$conn = mysqli_connect("****", "*****", "***", "***") or die("Could not Connect");
$Reference_Number = $_POST['Reference Number'];

$sql = mysqli_query($conn, "SELECT Reference Number FROM Tickets");
$sql = mysqli_query($conn, "INSERT INTO Tickets (Reference Number) VALUES ('5')");

$result = mysqli_query($conn, $sql) or die("Connected Successfully! <br> However The Selected Query Failed");

I want to write to my database, I can read from it using a SELECT query fine, but writing seems impossible.

Does anyone know what's wrong with my code on a quick glance? Could I be mixing up my MySQL and MYSQLi or my PHP code? My server uses PHP 7.1 but I can change it down to 5.0 if need be.

It can run MYSQLi

I've also tried this

$conn = mysqli_connect("****", "****", "****", "****") or die("Could not Connect");
$Reference_Number = $_POST['Reference Number'];


$sql = "INSERT INTO Tickets (Reference Number) VALUES ('5')";

$result = mysqli_query($conn, $sql) or die("Connected Successfully <br> However The Selected Query Failed");

回答1:

The Reference Number col name is strange.

If it's real column name, use backticks around.

INSERT INTO  Tickets (`Reference Number`) VALUES (5);


标签: php mysqli