Jump to content

Recommended Posts

i'm having trouble updating an image in my db.

my code is as follows

 

<?php 

include('settings.php'); 
// Make sure the user actually 
// selected and uploaded a file

if(isset($_COOKIE['ID_my_site'])) 
{ 
$usernamecookie = $_COOKIE['ID_my_site']; 
}

if(is_numeric($_GET['user'])){

$id = $_GET['user'];
}

$name = mysql_real_escape_string($_POST['usernamecookie']);
$idpic = mysql_real_escape_string($_POST['iduser']);

if (isset($_POST['submit']) && ($_FILES['image']) && $_FILES['image']['size'] > 0) { 
  
  // Temporary file name stored on the server
      $tmpName  = $_FILES['image']['tmp_name']; 
  $fileType = $_FILES['image']['type'];
      
  
  // Read the file 
      $fp   = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);
      

      // Create the query and insert
      // into our database.
      $query = "UPDATE `tbl_images` SET `image` = '" . $data . "', `filetype` = '" . $fileType . "' WHERE `userid` = '" . $idpic . "'";
      $results = mysql_query($query) or die(mysql_error());
      
      // Print results
      print "Thank you, your file has been uploaded.";
  
  }else{
	  echo "no photo uploaded";

}
// Close our MySQL Link
mysql_close($link);
?>

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="512000000000" type="hidden">
<input name="image" accept="image/jpeg" type="file">
<tr><td><?php echo "<input type='hidden' name='usernamecookie' value='$usernamecookie'>"?></tr></td>
<tr><td><?php echo "<input type='hidden' name='iduser' value='$id'>"?></td>
<input value="Submit" type="submit" name="submit">

Link to comment
https://forums.phpfreaks.com/topic/151448-solved-cant-update-image/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.