Hello to all,
Please tell me the error from the following code. When I choose a file from 'file' field, then it update the image, but when I dont choose a file. It doesn't keep the same image, i.e. the image get disappear. What is the problem in my 'If.....else code'.
Please, help me.
//edit-demo2.php
<?php
//session_start();
$con=mysql_connect("localhost","root","");
$db=mysql_select_db('admin');
$pid = $_GET['id'];
$select= "SELECT * FROM gallery where id='$pid'";
$query = mysql_query($select);
//echo $rsprofiles;
$row = mysql_fetch_array($query);
//$a=$_POST['current'];
//echo "current file :".$a;
$submit=$_POST['submit'];
if(!empty($submit))
{
$pid1=$_POST['pid'];
$title=$_POST['title'];
$file=time().$_FILES['file']['name'];
if(!empty($file))
{
$file_new=move_uploaded_file($_FILES["file"]["tmp_name"],
"upload-img/" .$file);
//echo "Stored in: " . "upload-img/" . $_FILES["file"]["name"];
$update=mysql_query("update gallery set title='$title',file='$file' where id='$pid1'");
}
else
{
$file_old=$_POST['current'];
$update=mysql_query("update gallery set title='$title',file='$file_old' where id='$pid1'");
}
header("Location: manage.php");
}
?>
<body>
<form action="edit-demo2.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="pid" id="pid" value="<?php echo $row['id']; ?>" />
<p align="center">Title: <input type="text" name="title" id="title" value="<?php echo $row['title']; ?>" /></p>
<p align="center">Image :<input type="file" name="file" id="file" /><input type="text" name="current" id="current" value="<?php echo $row['file']; ?>" /><img src="upload-img/<?php echo $row['file']; ?>" height="110" width="110" /></p>
<p align="center"> <input type="submit" name="submit" id="submit" value="submit" /><a href="manage.php">Show</a></p>
</form>
</body>