5

I faced an error, I want to take username from member table and image path from uploading directory and my image is is autoincrement.

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

I got following error

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

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"]["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."; } } ?> 
9
  • The query isn't in the correct order. What are you up to? Share the scenario. Commented Oct 1, 2016 at 7:55
  • I want to make profile page when user upload photo his photo store to directory and when user loggedin particular image with required info should be displayed Commented Oct 1, 2016 at 8:09
  • Then the above query seems totally different. That shouldn't be about insert query, I guess. I hope, you are using session to log in. Just pass the user id to the query and get the required profile image for the user. Commented Oct 1, 2016 at 8:11
  • Sir check my php script for uploading image Commented Oct 1, 2016 at 8:14
  • i want to save it in database Commented Oct 1, 2016 at 8:14

1 Answer 1

1

You should be using the following to select with insert:

INSERT INTO ProfileImage(col1, col2) SELECT col1, col2 FROM member m INNER JOIN AnyTable k ON m.Col1 = k.Col1 WHERE m.username = 'John' 

Note: The column numbers must be the same.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.