1 Replies - 340 Views - Last Post: 16 May 2013 - 02:16 AM Rate Topic: -----

#1 rayna  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-May 13

Unable to update image

Posted 15 May 2013 - 08:15 PM

Hi. I'm trying to replace an image in database where the user already has an image in the database. This is my update.php
 <p align="center"><form name="form1" method="post" action="update_process.php">
  <table width="500" border="0" align="center" cellpadding="1" cellspacing="1">
    <tr> 
      <td colspan="2" bgcolor="#0066FF"><div align="center" class="style1">UPDATE PATIENT PROFILE </div></td>
    </tr>
    <tr> 
      <td width="105" bgcolor="#CCCCCC"><div align="right">Username</div></td>
      <td width="388" bgcolor="#CCCCCC"><input name="user" type="text" id="user" size="25" value="<?php echo $data['username']; ?>" DISABLED></td>
    </tr>
    <tr> 
      <td bgcolor="#CCCCCC"><div align="right">Password</div></td>
      <td bgcolor="#CCCCCC"><input name="pwd" type="pwd" id="pwd" size="25" value="<?php echo $data['password']; ?>" ></td>
    </tr>
    <tr> 
      <td bgcolor="#CCCCCC"><div align="right">First Name</div></td>
      <td bgcolor="#CCCCCC"><input name="fname" type="text" id="fname" size="70" value="<?php echo $data['fname']; ?>"></td>
    </tr>
    <tr> 
      <td bgcolor="#CCCCCC"><div align="right">Last Name</div></td>
      <td bgcolor="#CCCCCC"><input name="lname" type="text" id="lname" size="70" value="<?php echo $data['lname']; ?>"></td>
    </tr>
     <tr> 
      <td bgcolor="#CCCCCC"><div align="right">IC</div></td>
      <td bgcolor="#CCCCCC"><input name="ic" type="text" id="ic" size="25" value="<?php echo $data['ic']; ?>"></td>
    </tr>
    <tr> 
      <td bgcolor="#CCCCCC"><div align="right">Address</div></td>
      <td bgcolor="#CCCCCC"><input name="add" type="text" id="add" size="70" value="<?php echo $data['address']; ?>"></td>
    </tr>
   
    <tr> 
      <td bgcolor="#CCCCCC"><div align="right">Phone</div></td>
      <td bgcolor="#CCCCCC"><input name="phone" type="text" id="phone" size="25" value="<?php echo $data['phone']; ?>"></td>
    </tr>
    <tr> 
      <td bgcolor="#CCCCCC"><div align="right">Email</div></td>
      <td bgcolor="#CCCCCC"><input name="email" type="text" id="email" size="35" value="<?php echo $data['email']; ?>"></td>
    </tr>
    <tr> 
      <td bgcolor="#CCCCCC"><div align="right">Image</div></td>
      <td bgcolor="#CCCCCC"><input type="file" name="file">
        Upload your image here</td>
    </tr>

    <tr>
      <td colspan="2"><div align="center">
        <input type="submit" name="Submit2" value="Update">
      </div></td>
    </tr>
  </table> </form>


This is the update_process.php
<?php
mysql_connect("localhost","root","*****")or die(mysql_error());
mysql_select_db("admin");
$user=$_COOKIE["test"];


		
		$password=$_POST["pwd"];
		$fname=$_POST["fname"];
		$lname=$_POST["lname"];
		$ic=$_POST["ic"];
		$add=$_POST["add"];
		$phone=$_POST["phone"];
		$email=$_POST["email"];
		$image=$_FILES['image']['name'];
		$target = "images/"; 
		$target = $target . basename( $_FILES['image']['name']);
		$query = "UPDATE patient SET image='$image' WHERE username='$user'";

$query = "update patient SET password ='$password', fname='$fname', lname='$lname', ic='$ic',address='$add',phone='$phone',email='$email' where username='$user'";
mysql_query($query) or die(mysql_error());
echo "<script>
alert('Your profile has been succesfully updated.');
window.location = 'update.php';
</SCRIPT>";

?>



Username,password update perfectly fine in the database, but the image didn't update. Plus, it delete the original image in the database.My intention is that user can upload any image from any folder, and when it is updated, the image will be saved in the folder that I've specified for the image of users(which is user folder). I've tried transfer_image too but it didn't work too. What do you think I've done wrong?

This post has been edited by macosxnerd101: 15 May 2013 - 08:36 PM
Reason for edit:: Removed password


Is This A Good Question/Topic? 0
  • +

Replies To: Unable to update image

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3838
  • View blog
  • Posts: 13,595
  • Joined: 12-December 12

Re: Unable to update image

Posted 16 May 2013 - 02:16 AM

You create $query but don't execute it, immediately replacing it with the second query.

BTW
Using alerts is discouraged and it would be preferable to use PHP header() to redirect.
The mysql library is deprecated - see my signature.
You should not be inserting unchecked, and unsanitised, data directly into a database. Use parameterized queries in preference.
Your HTML uses many attributes (bgcolor, align, the name attribute of a form) that are either deprecated or obsolete; use css instead.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1