创建发布和评论系统后,我添加了图片上传功能并收到此错误消息
错误:无法执行INSERT INTO帖子(用户名,图像,新闻,subreddit,标题)VALUES(“ testing1”,“ koth.gif”测试”,“ m”,“图像”)。您的SQL语法有误;检查与您的MariaDB服务器版本相对应的手册以获取在第1行的'test','m','Image')'附近使用的正确语法
我尝试修改INSERT命令的顺序,还尝试通过更改图像上载代码来修复它。最后,我检查了上传文件夹的权限是否正确。我的目标是使图像随我的帖子一起上传。
给我错误的代码部分:
$username = $_SESSION['userID'];
$title = mysqli_real_escape_string($link, $_REQUEST['title']);
$content = mysqli_real_escape_string($link, $_REQUEST['content']);
// Get image name
$image = $_FILES['image']['name'];
$target = "uploads/".basename($image);
//$subreddit = mysqli_real_escape_string($link, $_REQUEST['subreddit']);
$subreddit = 'm';
$posttype = '1';
if ($title === '' || $content === '') {
echo '<script>document.getElementById("failure").innerHTML = "<p>Title or post content not entered.</p>";</script>';
} else {
// attempt insert query execution
$sql = "INSERT INTO posts (username, image, news, subreddit, title) VALUES ('$username', '$image' $content', '$subreddit', '$title')";
if(mysqli_query($link, $sql)) {
// echo "Records added successfully.";
$msg = 'Post submitted successfully!';
echo "<script> window.location.assign('m.php'); </script>";
You miss a comma and a single quote before
$content
缺少引号和逗号
INSERT INTO帖子(用户名,图像,新闻,subreddit,标题)VALUES(“ testing1”,“ koth.gif”,“ test”,“ m”,“ Image”)
INSERT INTO帖子(用户名,图像,新闻,subreddit,标题)VALUES('$ username','$ image','$ content','$ subreddit','$ title')