内部连接MySQL查询错误
问题描述:
我遇到了一个错误,我想从上传目录的成员表和图像路径中获取用户名,我的图像是自动增量。内部连接MySQL查询错误
INSERT INTO profileimage SET
`imageid`='',
`username`='username',
`imagepath`='$target_file'
inner join member
on profileimage.username=member.username;
我得到了以下错误
1064 - 你在你的SQL语法错误;检查对应于你的MySQL服务器版本的手册正确的语法使用近在行“内部联接上profileimage.username = member.username成员” 5
我的PHP脚本在这里
<?php
error_reporting(E_ALL^E_NOTICE);
include('configdb.php');
if (isset($_POST['submit'])) {
$target_dir = "../Photos/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["file"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
$target_file = $target_dir . rand(1,100000) . basename($_FILES["file"]["name"]);
$uploadOk = 1;
}
if ($_FILES["file"]["size"] > 600000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif") {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else
if(move_uploaded_file($_FILES["file"]["tmp_name"], $$target_dir.$target_file))
{
$QueryInsertFile="INSERT INTO imgstore SET
`imgpath`='$target_file'";
}
else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
答
您应该使用以下具有插入选择:
INSERT INTO ProfileImage(col1, col2)
SELECT col1, col2
FROM member m INNER JOIN AnyTable k
ON m.Col1 = k.Col1
WHERE m.username = 'John'
注:列数必须相同。
查询的顺序不正确。你要做什么?分享场景。 –
我想创建个人资料页面,当用户上传照片他的照片商店目录和当用户登录特定图像与所需的信息应显示 – Marina
然后上述查询似乎完全不同。这应该不是关于插入查询,我猜。我希望您使用会话进行登录。只需将用户标识传递给查询并获取用户所需的配置文件映像即可。 –