php - upload image to server and saving url to server -


i building image uploader, upload image server , replacing old image url in database new one. upload part working perfectly, unable imageurl in database. can take @ code please , tell me i'm doing wrong?

<?php $target_dir = "media/images/"; $target_file = $target_dir . basename($_files["filetoupload"]["name"]); $uploadok = 1; $imagefiletype = pathinfo($target_file, pathinfo_extension); // check if image file actual image or fake image  if(isset($_post["uploadimage"])) {      $check = getimagesize($_files["filetoupload"]["tmp_name"]);       if ($check != false) {          echo "file image - " .$check["mime"]. ".";        $uploadok = 1;       } else {          echo "file not image";          $uploadok = 0;      }  }   // check if file exists   if (file_exists($target_file)) {    echo "sorry file exists";       $uploadok = 0;  }    // check fle size   if ($_files["filetoupload"]["size"] > 5000000) {      echo "sorry file large.";     $uploadok = 0;  }   // allow file formats  if ($imagefiletype != "jpg" && $imagefiletype != "png" &&     $imagefiletype != "jpeg" && $imagefiletype != "gif") {  echo "sorry, jpg, jpeg, png , gif files allowed.";  $uploadok == 0; }  // check if $uploadok set 0 error  if ($uploadok == 0) {      echo "sorry file not uploaded.";      // if ok try upload file   } else {      if (move_uploaded_file($_files["filetoupload"]["tmp_name"],  $target_file)) {      echo "the file ". basename($_files["filetoupload"]["name"]). " has      been uploaded.";      include 'connect.php';      $stmt = $conn->prepare("insert image(name,imageurl, image_cat_id, albumid) values (home1, ?, 8, 0)");      $stmt->bind_param('s', $target_file);     $stmt->execute();     $stmt->close();  } else {      echo "sorry, there error uploading file.";  }   }  ?> 

result on successful upload:

file image - image/png.the file arrowdown_51.png has been uploaded. fatal error: call member function bind_param() on boolean in c:\xampp\htdocs\webdevelopment\mosta dynamic\cms\upload.php on line 47

it's possible, function prepare() returns boolean value ... guess, made mistake in sql-query. try following:

insert image(name,imageurl, image_cat_id, albumid) values ('home1', ?, '8', '0') 

edit: if above query not persists records: check also, if names of columns (and table) correct.

please excuse bad english, i'm not native speaker ... :)


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -