I am trying to connect to an internal database through PHP. However, it gives me an error when trying to insert something, which looks like this:
Error: INSERT INTO id329521_server1.us (name, eml, pwd, fct, mon) VALUES (username, emailadress@gmail.com, 123, NULL, '100')
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, 123, NULL, '100')' at line 1
My code looks like this:
$name = $_POST["name"];
$email = $_POST["email"];
$pwd = $_POST["pwd"];
$servername = "localhost";
$username = "genericUsername";
$password = "genericPassword";
$dbname = "genericDBName";
// Create connection
if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
echo 'We don\'t have mysqli!!!';
} else {
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "INSERT INTO genericTableName (name, eml, pwd, fct, mon) VALUES ($name, $email, $pwd, NULL, '100')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}