Update data in MySQL without change of exists file

Update data in MySQL without change of exists file


Sometimes when you update the data but not able to upload the file and file (which is already in the database) is automatically removed. So, if you want to update only the data but not the file in the database then you can use the below code:

$connect=mysql_connect("hostname","username","password") or die ("connection failed");

$query="UPDATE users SET name='$name',email='$email',image='name' WHERE id=1";
$query="UPDATE users SET name='$name',email='$email' WHERE id=1";
$msg="Your profile has been updated.";
$msg="Error occurred....";



$sql=mysql_query("select * from users where id=1");


<form action="" method="post">
Profile Image: <img src="images/<?php echo $image; ?>" style="width:50px; height:50px;"><br>
Name: <input type="text" name="name" value="<?php echo $name; ?>"><br>
Email: <input type="email" name="email" value="<?php echo $email; ?>"><br>
Upload Image: <input type="file" name="image">

<input type="submit" name="submit" value="Click Here">

In this code the following methods and SQL statements are used to update the existing records:

* post()
* IsSet string
* update statement with where clause
* select statement
* SQL query function

Explanation of the code
We have used post method because unlimited data i.e. both text and binary data, can be easily passed through post method and it is more secure.

The update statement is used for the existing record's modification. Along with the update statement, where clause is joined together to apply the modification of those records that match the particular criteria. After the update statement, we have executed the respective query by integrating it to the PHP SQL query() function in order to update records of the table.

Best WordPress Hosting


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price

Leave a Reply

    Waiting for your comments