image - Upload on server via php error -


i'm trying create upload form in can load image , path of image saved on database. of course, not working far!! code use:

<?php include("db_connect.php");      function getimageextension($imagetype)      {        if(empty($imagetype)) return false;        switch($imagetype)        {            case 'image/bmp': return '.bmp';            case 'image/gif': return '.gif';            case 'image/jpeg': return '.jpg';            case 'image/png': return '.png';            default: return false;        }      }    if (!empty($_files["uploadedimage"]["name"])) {      $file_name=$_files["uploadedimage"]["name"];     $temp_name=$_files["uploadedimage"]["tmp_name"];     $imgtype=$_files["uploadedimage"]["type"];     $ext= getimageextension($imgtype);     $imagename=date("d-m-y")."-".time().$ext;     $target_path = "images/".$imagename;   if(move_uploaded_file($temp_name, $target_path)) {      $query_upload="insert 'walls' ('images_path','submission_date') values ('".$target_path."','".date("y-m-d")."')";     mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error());    }else{     exit("error while uploading image on server"); }   }  ?> <h1>image uploader</h1> <form action="uploader.php" enctype="multipart/form-data" method="post">  <table style="border-collapse: collapse; font: 12px tahoma;" border="1" cellspacing="5" cellpadding="5"> <tbody><tr> <td> <input name="uploadedimage" type="file"> </td>  </tr>  <tr> <td> <input name="upload now" type="submit" value="upload image"> </td> </tr>   </tbody></table>  </form> 

the db_connect.php

<?php      $sql_servername = "localhost";     $sql_user = "***";     $sql_pass = "***";     $sql_db_name = "***";      // connect mysql server     $db = new mysqli($sql_servername, $sql_user, $sql_pass, $sql_db_name);     if (!$db) {         die('could not connect db: ' . mysql_error());     }  ?> 

of course can't show credentials i'm sure @ 100% correct , there aren't problem! when try upload message:

error while uploading image on server 

but can't understand why , how solve. idea? thanks

try using:

$query_upload = "insert walls (images_path, submission_date) values ('".$target_path."','".date("y-m-d")."')"; 

you shouldn't surround table/column names in quotes, if want to, should use backticks, isn't required.

then alter query use either oop:

$db->query($query_upload) or die($db->error); 

or procedural style:

mysqli_query($db, $query_upload) or die(mysqli_error($db)); 

instead of deprecated mysql_query() function.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -