dseigqk7443 2016-10-03 08:41
浏览 7

mySql查询问题? [重复]

This question already has an answer here:

I want to display data from two table all required information from Member table and photos from profile image file now i want to save profile photo address to database but i got error my php script is here

<?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"]["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"]["name"], $$target_dir.$target_file))
                {    
            mysqli_query($conn,"INSERT INTO profileimage  VALUES ('','".$target_file."',''") select p.imageid, p.username,p.imagepath from profileimage p
            innerjoin member m
            on m.username=p.username;

      or die(mysqli_error($conn));
                }
                else {
        echo "Sorry, there was an error uploading your file.";
    }

}
?>

i have write my query like

 mysqli_query($conn,"INSERT INTO profileimage  VALUES ('','".$target_file."',''") select p.imageid, p.username,p.imagepath from profileimage p
        innerjoin member m
        on m.username=p.username;

i got an error ( ! ) Parse error: syntax error, unexpected 'select' (T_STRING) in C:\wamp\www\uploadegistration\uploadprofile.php on line 46

how should i do that usernamer is foriegn key from member table

</div>
  • 写回答

2条回答 默认 最新

  • doumi1944 2016-10-03 08:47
    关注
    mysqli_query($conn,"INSERT INTO profileimage  select p.imageid, ".$target_file.",p.imagepath from profileimage p
            innerjoin member m
            on m.username=p.username;
    
        // Remove Value portion And add $target_file value into select query. If you have to insert into perticular field then you have to mention field list also
    

    Example

    INSERT INTO Customers (CustomerName, Country)
    SELECT SupplierName, Country FROM Suppliers;
    
    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接