【发布时间】:2017-09-30 17:54:29
【问题描述】:
<html>
<body>
<form method = 'post' action= 'pt.php'>
<input type = 'text' name = 'name' placeholder = 'name'><br>
<textarea name = 'comment' cols = '40' rows = '10' placeholder = 'comment'></textarea><br>
<input type = 'submit' value = 'submit' name ='submit'><br>
</form>
</body>
</html>
<?php
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<br>";
}else{
$sql=$conn->query("INSERT INTO komen (nama, komment) VALUES ('$name','$comment')");
if($conn->query($sql) == TRUE){
echo "berhasil ditambahkan";
}
else
{
echo "error".$sql."<br>".$conn->error;
}
}
}
if($result=$conn->query("SELECT * FROM komen")){
$count = $result->num_rows;
echo 'Total '.$count.' komen <br><br>';
while ($rows=$result->fetch_object()){
echo '<strong>'.$rows->nama.'></strong>'.'<br>'.$rows->komment.'<br><br><br>';
}
$conn->close();
}
?>
我仍然收到错误“error1 您的 SQL 语法有错误;查看与您的 MariaDB 服务器版本相对应的手册,了解在第 1 行“1”附近使用的正确语法。
你能帮我解决这个问题吗? 非常感谢。
【问题讨论】:
-
给出的答案都没有解释为什么你会得到
near '1'。查阅副本;它已被解释,让您了解“为什么”。