Whats the issue in the following query....i am constantly receiving this error. Error: INSERT INTO Myguests (firstname,lastname,email)VALUES 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 '' at line 1
<?php include("new_db.php");?>
<?php
if(!empty($_POST['f_name'])&&!empty($_POST['l_name'])
&&!empty($_POST['email']))
{ $sql = "INSERT INTO Myguests (firstname,lastname,email)VALUES";
for($i=0;$i<$_POST['num'];$i++){
$first_name = mysqli_real_escape_string($conn,$_POST['f_name'][$i]);
$last_name = mysqli_real_escape_string($conn,$_POST['l_name'][$i]);
$Email = mysqli_real_escape_string($conn,$_POST['email'][$i]);
$sql.="('".$first_name."','".$last_name."','".$Email."')";
}
$sql =rtrim($sql, ',');
if (mysqli_query($conn, $sql)) {
echo "Records Created";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
mysqli_close($conn);
?>