php - editing image by using input file type -


i made simple editing edit data in mysql, works fine except when want edit input file type image doesn't work, doesn't give error message doesn't edit , when remove input file type image works. , editing image mean entering new image replace old image.

here code:

<?php  require("db.php");  $id     = $_request['theid']; $result = mysql_query("select * table id  = '$id'"); $test   = mysql_fetch_array($result);  $name   = $test['name'] ; $email  = $test['email'] ;                   $image  = $test['image'] ;  if (isset($_post['submit'])) {        $name_save  = $_post['name'];     $email_save = $_post['email'];      if (isset($_files['image']['tmp_name']))     {         $file       = $_files['image']['tmp_name'];         $image      = addslashes(file_get_contents($_files['image']['tmp_name']));         $image_name = addslashes($_files['image']['name']);          move_uploaded_file($_files["image"]["tmp_name"],"photos/" . $_files["image"]["name"]);         $image_save ="photos/" . $_files["image"]["name"];          mysql_query("update table set name ='$name_save', email  ='$email_save',image ='$image_save' id = '$id'") or die(mysql_error());           header("location: index.php");     } } ?>    <form method="post">     <table>         <tr>             <td>name:</td>             <td>                 <input type="text" name="name" value="<?php echo $name ?>"/>             </td>         </tr>         <tr>             <td>email</td>             <td>                 <input type="text" name="email" value="<?php echo $email ?>"/>             </td>         </tr>         <tr>             <td>image</td>             <td>                 <input type="file" name="image" value="<?php echo $image ?>"/>             </td>         </tr>         <tr>             <td>&nbsp;</td>             <td>                 <input type="submit" name="submit" value="submit" />             </td>         </tr>     </table> 

in form enctype="multipart/form-data" missing , in form there no type="file".

give below code , try.

<?php require("db.php"); $id =$_request['theid'];  $result = mysql_query("select * table id  = '$id'"); $test = mysql_fetch_array($result);  $name=$test['name'] ; $email= $test['email'] ;                     $image=$test['image'] ;  if(isset($_post['submit'])){     $name_save = $_post['name']; $email_save = $_post['email']; $image_save=$image //added if image not chose form post  if (isset($_files['image']['tmp_name'])) { $file=$_files['image']['tmp_name']; $image= addslashes(file_get_contents($_files['image']['tmp_name'])); $image_name= addslashes($_files['image']['name']); move_uploaded_file($_files["image"]["tmp_name"],"photos/" . $_files["image"]["name"]); $image_save ="photos/" . $_files["image"]["name"]; } mysql_query("update table set name ='$name_save', email  ='$email_save',image ='$image_save' id = '$id'") or die(mysql_error());  header("location: index.php");      } ?>    <form method="post" enctype="multipart/form-data"> <table> <tr> <td>name:</td> <td><input type="text" name="name" value="<?php echo $name ?>"/></td> </tr> <tr> <td>email</td> <td><input type="text" name="email" value="<?php echo $email ?>"/></td> </tr>  <tr> <td>image</td> <td><input type="file" name="image" /></td> </tr> <tr> <td>&nbsp;</td> <td><input type="submit" name="submit" value="submit" /></td> </tr> </table> 

moreover should previous image value through sql , update if image not chose while updating.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -