我想显示来自两个表的数据会员表中的所有必需信息以及来自个人资料图片文件的照片现在我想将个人资料照片地址保存到数据库但我收到错误 我的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"]["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.";
}
}
?>
我写了像
这样的查询 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;
我收到了一个错误 (!)解析错误:语法错误,第46行C:\ wamp \ www \ upload \ registration \ uploadprofile.php中的意外'选择'(T_STRING)
我该怎么做用户名是来自会员表的foriegn密钥
答案 0 :(得分:0)
查询中有额外的双引号(&#34;)
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));
答案 1 :(得分:-1)
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
示例强>
INSERT INTO Customers (CustomerName, Country)
SELECT SupplierName, Country FROM Suppliers;