MySQL Forums
Forum List  »  PHP

Mysql insert doesn't working but no notification appears
Posted by: Iris Lauer
Date: July 13, 2018 06:45AM

My table has 2 fields a primary with auto increment and then entry_id

why does the below not insert in the table:

-----------------------------------------------
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ecolog";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$entry_id = 5;

$sql = "INSERT INTO orders (entry_id) VALUE ('$entry_id')";


$conn->close();
?>
---------------------


but when adding a error check it does?

---------------------------------------------
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ecolog";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$entry_id = 5;

$sql = "INSERT INTO orders (entry_id) VALUE ('$entry_id')";
if ($conn->query($sql) === TRUE) {
echo "";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>
-------------------------------------------


cant get my head around why this would be happening.

Options: ReplyQuote


Subject
Written By
Posted
Mysql insert doesn't working but no notification appears
July 13, 2018 06:45AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.