发送到Serer时的PHP电子邮件语法

时间:2019-07-06 05:45:25

标签: php mysql server

我正在尝试将记录添加到数据库的表中。我收到错误消息:

Error: INSERT INTO Users (firstname, lastname, email) VALUES (John, Doe, someemail@gmail.com)
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '@gmail.com)' at line 2

这是我的代码:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname="users";
$conn = new mysqli($servername, $username, $password, $dbname);
$name='John';
$familyName='Doe';
$email='someemail@gmail.com';
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO Users (firstname, lastname, email)
VALUES ($name, $familyName, $email)";

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

$conn->close();
?>

我的目标是使用变量来传递数据。我在做什么错了?

0 个答案:

没有答案