require 'submit.php';
if (isset($_POST['submit'])){
$name= mysqli_real_escape_string($conn, $_POST['name']);
$comment = mysqli_real_escape_string($conn, $_POST['comment']);
if (empty($name) || empty($comment)){
echo "all fields must be filled
";
}else{
$sql=$conn->query("INSERT INTO komen (nama, komment) VALUES ('$name','$comment')");
if($conn->query($sql) == TRUE){
echo "berhasil ditambahkan";
}
else
{
echo "error".$sql."
".$conn->error;
}
}
}
if($result=$conn->query("SELECT * FROM komen")){
$count = $result->num_rows;
echo 'Total '.$count.' komen
';
while ($rows=$result->fetch_object()){
echo ''.$rows->nama.'>'.'
'.$rows->komment.'
';
}
$conn->close();
}
?>
I still get error "error1
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 '1' at line 1".
could you help me through this?
many thanks.
Answer
Try doing it this way
$sql="INSERT INTO komen (nama, komment) VALUES ('$name','$comment')";
if($conn->query($sql) == TRUE){
echo "berhasil ditambahkan";
}
else
{
echo "error".$sql."
".$conn->error;
}
No comments:
Post a Comment