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>
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;
There was extra double quote (") in query
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));