Thursday 8 August 2019

php - MariaDB server version for the right syntax to use near '1'



















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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...