php - I want to update the values but i dont want to change image when i update image is remove -


i updating form values . image uploaded , can see on form. when update text value image remove , showing blank.means not remains same when update remove automatically think not getting path current image value when updating other values. kindly me sort out problem if have update name of person change name , other fields remains same. when click on update values remains same , update 1 update problem photo remove not remain same

<?php  $v_id = $_get['v_id']; include "config.php";  $sql = "select * my_veh_ven v_id='$v_id'"; $result = mysqli_query($conn,$sql); if(mysqli_num_rows($result)>0) {   while($row = mysqli_fetch_assoc($result)) {   ?>         <!-- form start -->         <form role="form" method="post" action="updatevehicle.php?v_id=<?= $row["v_id"] ?>" enctype="multipart/form-data">           <div class="box-body">               <div class="form-group col-md-offset-0 col-md-4">               <label for="">25+ days rent in pkr</label>               <input type="text" class="form-control" name="v_25_plus_rent" value="<?=$row["v_25_plus_rent"]?>">             </div>                <div class="form-group col-md-offset-0 col-md-8">               <label >change vehicle picture</label>               <input  type="file"  name="image" id="myfile" value="images/<?=$row["image"]?>" accept="image/*">             </div>               <div class="form-group col-md-offset-0 col-md-4" style="text-align: center;">               <label for="exampleinputfile" style="text-align: center;" >current vehicle picture</label>               <?php echo'<image src="images/'.$row["image"].'" style="width:325px;height:220px;"></image>'; ?>             </div>              <div class=" ">               <div class=" with-border" style="text-align:center;">                 <h4 class="box-title" style="text-align:center;"><b>vendor details</b></h4>               </div>             </div>             </div>           <!-- /.box-body -->            <div class="box-footer skin-yellow">             <button type="submit" name="submit" class="btn btn-primary skin-yellow">update</button>           </div>         </form>         <?php     }   } else {     echo "sorry wrong"; }  mysqli_close($conn); ?> 

updating file

   <?php include "config.php"; if(isset($_post['submit']))   {      $target = "images/".basename($_files['image']['name']);    $v_type = $_post["v_type"];    $v_name = $_post["v_name"];    $v_man = $_post["v_man"];    $v_model = $_post["v_model"];    $v_color = $_post["v_color"];    $v_trans = $_post["v_trans"];    $v_1_15_rent = $_post["v_1_15_rent"];    $v_16_25_rent = $_post["v_16_25_rent"];    $v_25_plus_rent = $_post["v_25_plus_rent"];    $v_reg = $_post["v_reg"];    $vendor_name = $_post["vendor_name"];    $vendor_mobile = $_post["vendor_mobile"];    $vendor_price = $_post["vendor_price"];    $image = $_files["image"]["name"];    $v_id=$_get["v_id"];     $sql = " update my_veh_ven set v_type='$v_type', v_name='$v_name' ,v_man='$v_man' ,v_color='$v_color', v_trans='$v_trans',  v_1_15_rent='$v_1_15_rent' , v_16_25_rent='$v_16_25_rent' ,v_25_plus_rent='$v_25_plus_rent' , image='$image' , v_reg='$v_reg' ,vendor_name='$vendor_name', vendor_mobile='$vendor_mobile' ,vendor_price='$vendor_price'  v_id='$v_id' ";    if (mysqli_query($conn, $sql))      {          if(move_uploaded_file($_files['image']['tmp_name'], $target))                 {                 $success = "✓ updated";                 }     }   else    {                 $fail = "x  not updated";    }    }      mysqli_close($conn);   ?> 

an <input type="file"/> has no value attribute usage. image, once uploaded, on server , that's it. cannot set value of input meaningful.

what want display uploaded picture instead of input, , present input if user wants change it.

edit: have php code, can see overwriting $image variable if empty

$image = $_files["image"]["name"]; 

you have verify if $_files["image"] exists, else image null or undefined. , update database bad value. suggest treat upload differently other data:

<?php include "config.php"; if(isset($_post['submit']))   {      $target = "images/".basename($_files['image']['name']);    $v_type = $_post["v_type"];    $v_name = $_post["v_name"];    $v_man = $_post["v_man"];    $v_model = $_post["v_model"];    $v_color = $_post["v_color"];    $v_trans = $_post["v_trans"];    $v_1_15_rent = $_post["v_1_15_rent"];    $v_16_25_rent = $_post["v_16_25_rent"];    $v_25_plus_rent = $_post["v_25_plus_rent"];    $v_reg = $_post["v_reg"];    $vendor_name = $_post["vendor_name"];    $vendor_mobile = $_post["vendor_mobile"];    $vendor_price = $_post["vendor_price"];     $v_id=$_get["v_id"];     $sql = " update my_veh_ven set v_type='$v_type', v_name='$v_name' ,v_man='$v_man' ,v_color='$v_color', v_trans='$v_trans',  v_1_15_rent='$v_1_15_rent' , v_16_25_rent='$v_16_25_rent' ,v_25_plus_rent='$v_25_plus_rent' , v_reg='$v_reg' ,vendor_name='$vendor_name', vendor_mobile='$vendor_mobile' ,vendor_price='$vendor_price'  v_id='$v_id' ";    if (mysqli_query($conn, $sql))      {          if(move_uploaded_file($_files['image']['tmp_name'], $target))                 {                 $image = $_files["image"]["name"];                 $success = "✓ updated";                 $sql = "update my_veh_ven set image='$image' v_id='$v_id' ";                 mysqli_query($conn, $sql)                 }     }   else    {                 $fail = "x  not updated";    }    }      mysqli_close($conn);   ?> 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -