SQL query doesn't work

0 Steven the awesome · May 29, 2015

INSERT INTO `pictures_upload`(`path_profile_picture`, `path_banner_picture`, `persoons_id`) VALUES ('', '$this->path2', '') WHERE persoons_id='$fetch_data[id]'

$fetch_data[2]                   Should be number 2
path_banner_picture       Should be the path to the image


It gave me this 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 'WHERE `persoons_id`='2'' at line 1 

Post a Reply

Replies

Oldest  Newest  Rating
+1 mike richardson · May 29, 2015
It happens to the best of us!!! 
0 Steven the awesome · May 29, 2015
OMG this was so stupid, I should have known this, thank you so much!
0 mike richardson · May 29, 2015
"UPDATE pictures_upload SET path_banner_picture = ‘$this->path2’ WHERE persoons_id = '".$fetch_data['id']."'
+1 mike richardson · May 29, 2015
Then you need to use and UPDATE not INSERT you can not INSERT WHERE.
0 Steven the awesome · May 29, 2015
Because I want to insert data in 'path_banner_picture', but it only  has to be inserted in the one with the persoons_id equal to the session.
0 mike richardson · May 29, 2015
Why do you have a WHERE statement in your INSERT?
0 Steven the awesome · May 29, 2015
So this doesn't work either, so I made a if statement to see what error I get. And this what the error is saying.

query mislukt

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 'WHERE persoons_id='1'' at line 1

And this is my complete function


//De uiteindelijke uivoer van de afbeelding
public function uitvoer($type, $Verbinding, $tmp_name)
{
//het path naar de database folder
$this->path  = "database/";
$this->path2 = "database/$this->randomString$this->ext";
//info voor het id
$username = $_SESSION['username'];
$query = mysqli_query($Verbinding, "SELECT id FROM users WHERE Email='$username'");
$fetch_data = mysqli_fetch_array($query);

//query
$this->query = "INSERT INTO pictures_upload (path_profile_picture, path_banner_picture, persoons_id) VALUES ('', '$this->path2', '') WHERE persoons_id='".$fetch_data['id']."'";

if($this->run_query = mysqli_query($Verbinding, $this->query))
{
echo 'query gelukt ';
}else{
echo 'query mislukt'.mysqli_error($Verbinding);
}


//upload de file naar de database folder
if(move_uploaded_file($tmp_name, $this->path.$this->randomString . $this->ext))
{
echo 'gelukt!';
}else{
echo 'mislukt';
}


}
0 Gregory Ballantine · May 29, 2015
When you're using variables in strings, you need to use double quotes for those strings, not single quotes. Else, it is read as is (not as a variable).

This:
'$this->path2'

Should be
"$this->path2"

Same goes for
'$fetch_data[id]'

Should be

"$fetch_data[id]"
  • 1

SQL & Databases

107,035 followers
About

Everything SQL and Databases related in here!

Links
Moderators
Bucky Roberts Administrator