我不明白错误:
"警告:mysqli :: query():无法获取mysqli 第15行的var / www / html /.../addUser.php错误:未添加用户"
有人有解决方案的想法吗?
addUser.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include_once('config.php');
$name = $_POST['name'];
$firstname= $_POST['firstname'];
$email = $_POST['email'];
$sql = "INSERT INTO user(name, firstname, email) VALUES('$name', '$firstname', '$email')";
if($connection->query($sql) === TRUE){
echo 'User has been added';
}
else
{
echo 'error : User not added';
}
?>
的config.php
?php
define('DB_HOST', 'localhost');
define('DB_NAME', 'db');
define('DB_USERNAME', 'user');
define('DB_PASSWORD', '');
$connection = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME) or die("Could not connect to database");
if(mysqli_connect_errno()){
echo('Connection fail'.mysqli_connect_error());
exit();
}
$connection->close();
?>