php - inner join中的MySQL查询错误

标签 php mysql

我遇到了一个错误,我想从成员表中获取用户名,从上传目录中获取图像路径,我的图像是自动增量的。

             INSERT INTO profileimage  SET
                `imageid`='',
                    `username`='username',
                 `imagepath`='$target_file'
            inner join member
            on profileimage.username=member.username;

出现以下错误

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'inner join member on profileimage.username=member.username' at line 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'

注意:列号必须相同。

关于php - inner join中的MySQL查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39804145/

相关文章:

javascript - 使用 json_encode 将 php 变量转为 javascript

mysql : Algorithm to select most recent item per key in a history table

mysql - 更新 MySQL 中最高的自增主键

php - 选项值不显示在下拉菜单中?

javascript - 使用 laravel 和 ajax 部分页面重新加载

php - 如何在mysql中存储用户的头像

PHP 分页未返回预期结果

mysql - 在多列匹配上使用 "where"或 "inner join"

php - 如何执行安全查询 PHP

php - 有谁知道跟踪电子邮件阅读时间的方法?