How to Update Image in PHP with Demo in MySQL Database

By CampCodes Administrator

Published on:

how to update image in php with demo

Tutorial: How to Update Image in PHP with Demo in MySQL Database with Source Code

Getting Started on How to Update Image in PHP with Demo in MySQL Database

This is a tutorial on How to Update Image in PHP with Demo in MySQL Database. In this tutorial, we are going to update the current Image to a new one. For this tutorial, we are going to use the UPDATE Statement to update the current image in our table. Let’s start with: This is the image that we are going to edit.

how to update image in php with demo

Updating Image

Modal Form Field

<div id="delete<?php  echo $id;?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<h3 id="myModalLabel">Update</h3>
</div>
<div class="modal-body">
<div class="alert alert-danger">
<?php if($row['image_location'] != ""): ?>
<img src="uploads/<?php echo $row['image_location']; ?>" width="100px" height="100px" style="border:1px solid #333333; margin-left: 30px;">
<?php else: ?>
<img src="images/default.png" width="100px" height="100px" style="border:1px solid #333333; margin-left: 30px;">
<?php endif; ?>
<form action="edit_PDO.php<?php echo '?tbl_image_id='.$id; ?>" method="post" enctype="multipart/form-data">
<div style="color:blue; margin-left:150px; font-size:30px;">
	<input type="file" name="image" style="margin-top:-115px;">
</div>
</div>
<hr>
<div class="modal-footer">
<button class="btn btn-inverse" data-dismiss="modal" aria-hidden="true">No</button>
<button type="submit" name="submit" class="btn btn-danger">Yes</button>
</form>
</div>
</div>
</div>

Creating Our Database

<?php 
$conn = new PDO('mysql:host=localhost; dbname=upload_image','root', ''); 
?>

Creating Our UPDATE Statement

<?php
 
require_once ('db.php');
 
$get_id=$_REQUEST['tbl_image_id'];
 
move_uploaded_file($_FILES["image"]["tmp_name"],"uploads/" . $_FILES["image"]["name"]);			
$location1=$_FILES["image"]["name"];
 
 
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE tbl_image SET image_location ='$location1' WHERE tbl_image_id = '$get_id' ";
 
$conn->exec($sql);
echo "<script>alert('Successfully Updated!!!'); window.location='index.php'</script>";
?>

Output:

update image in php

Update The Current Image As you can see the current image was updated. How to Update Image in PHP with Demo in MySQL Database.

READ ALSO:   Delete Duplicate Object From Array In PHP

DEMO


Related Tutorials: Image Upload using Ajax in PHP, How to Upload an Image using AJAX in PHP and MySQLi, Change Image Name When Upload in PHP, How to Upload and Validate an Image File in PHP, Create Captcha Image in PHP, Image Upload Using PDO in PHP,

Download Here
how to add image in email php how to add image in php database how to add image in php file how to add image in php form how to add image in php page how to change background image in php how to change image background color in php how to change image dynamically in php how to change image extension in php how to change image in php how to change image in php mysql how to change image name in php how to change image size in php how to change size of image in php how to change the image in php how to create image in php example how to display image in php code how to display image in php from database how to display image in php from folder how to display image in php using path how to display image in php w3schools how to download image in php code how to echo image in php from database how to get image in php from database how to insert image in php database how to insert image in php form how to insert image in php html how to insert image in php mysql how to insert image in php using xampp how to insert image in php w3schools how to insert image in php web page how to put image in php code how to put image in php echo how to refresh captcha image in php how to resize image in php before upload how to resize image in php on upload how to resize image in php while uploading how to resize image in php with example how to rotate image in php code how to save image in php database how to save image in php upload how to store image in php database how to update a image in php how to update an image in php how to update blob image in php how to update existing image in php how to update image file in php how to update image in database and folder using php how to update image in database in php how to update image in database using php how to update image in mysql database using php source code how to update image in php and mysql how to update image in php code how to update image in php codeigniter how to update image in php database how to update image in php mysql how to update image in php mysql with demo how to update image in php mysqli how to update image in php using mysqli how to update image in php w3schools how to update image in php with demo how to update image using ajax in php how to update multiple image in php how to update old image if no image selected in php how to update the image in php how to upload image in oop php how to upload image in php code how to upload image in php codeigniter how to upload image in php database how to upload image in php laravel how to upload image in php localhost how to upload image in php mysql how to upload image in php mysql database how to upload image in php mysql with insert update delete operations how to upload image in php source code how to upload image in php stack overflow

Leave a Comment