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;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失