Jump to content

[SOLVED] Simple line of PHP not working!!! Should be v.simple...


spikypunker

Recommended Posts

All it is is this bit:

 

$query = "INSERT INTO USER (image) VALUES ('$filename') WHERE user='$user' ";

 

it should work, it's rreeeally simple but no joy!

 

IF i take out the

WHERE user='$user'

bit then it does actually insert into the mysql, it just starts a new entry...

 

I've done echo's of both variables and they come out fine. I've even tried replacing the $user with an actual column name that i know is there!!

 

Why doesnt it work!!!!!!

 

Here is the rest of the code (which all works perfectly, the image uploads just the MySql doesnt update)

 

 

<?php

$user = $_GET['user'];





if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
  
  $filename = basename($_FILES['uploaded_file']['name']);
  $ext = substr($filename, strrpos($filename, '.') + 1);
  if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && 
    ($_FILES["uploaded_file"]["size"] < 1000000)) {
    
      $newname = dirname(__FILE__).'/userpics/'.$filename;




      if (!file_exists($newname)) {
        
        if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
          
	  
	  
	  
	   mysql_connect ("localhost","","");
		@mysql_select_db("") or die ("unable to connect");

		$query = "INSERT INTO USER (image) VALUES ('$filename') WHERE user='$user' ";

		mysql_query($query);

		mysql_close();


		echo "It's done! The file has been saved as: ".$newname;




        } else {
           echo "Error: A problem occurred during file upload!";
        }
      } else {
         echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
      }
  } else {
     echo "Error: Only .jpg images under 350Kb are accepted for upload";
  }
} else {
echo "Error: No file uploaded";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.