CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   photo edit can't (http://www.codingforums.com/showthread.php?t=285310)

minkoko 01-05-2013 11:20 AM

photo edit can't
 
Hello.my Friend,Today i found some problem when edit my text and photo update
I have this dir

upload
list.php
edit.php

list.php
PHP Code:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <table border="1">
        <tr > <td>id </td>
              <td>Name </td>
               <td>email</td>
                <td>photo</td>
                <td>Edit</td>
        </tr>
        <?php
        $host
"localhost";
        
$name="root";
        
$pass="";
        
$db="test";
        
$con=mysql_connect($host,$name,$pass);
        
$seldb=mysql_select_db($db,$con);
        
$query=mysql_query("SELECT * FROM user");
        while(
$row=mysql_fetch_array($query)){
        
?>
        <tr>
            <td><?php echo $row['id']; ?></td>
            <td><?php echo $row['name']; ?></td>
            <td><?php echo $row['email']; ?></td>
            <td><img src="upload/<?php echo $row['photo']; ?>" width="100" height="100"/></td>
      <td>  <a href="edit.php?id=<?php echo $row[0]; ?>">Edit</a></td>
        </tr>
        <?
        
}
        
?>
        </table>
    </body>
</html>

edit.php
Code:

<?php

 $host= "localhost";
        $name="root";
        $pass="";
        $db="test";
        $con=mysql_connect($host,$name,$pass);
        $seldb=mysql_select_db($db,$con);
        $query=mysql_query("SELECT * FROM user");
        if(isset($_GET['id'])){
            $id=$_GET['id'];
            $query=mysql_query("SELECT * FROM user");
            while($row=  mysql_fetch_assoc($query)){
     
?>
<form action="edit.php" method="post" enctype='multipart/form-data'>
Name: <input type="text" name="name" value="<?php echo $row['name']; ?>"/>
Email : <input type="text" name="email" value="<?php echo $row['email']; ?>"/>
Photo: <input type="file" name="photo" value="upload/<?php echo $row['photo']; ?>"/>
<?php
        } }
        ?>
<input type="hidden" name="hid" value="<?php echo $row['id']; ?>"/>
<input type="submit" name="save" value="Update"/>
</form>
<?php
if(isset($_POST['save'])){
    $hid=$_POST['hid'];
    $name=$_POST['name'];
    $email=$_POST['email'];
    $photo=$_FILES['photo'];
   
  $update= mysql_query("UPDATE user SET name='$name',email='$email',photo='$photo' WHERE id='$hid'");
        move_uploaded_file($_FILES['photo']['tmp_name'], "upload/".$photo);
    if($update){
      echo "<meta http-equiv=refresh content=0,url=list.php>";
    }
}
?>

i just want to change text when i edit the text but my problem is,when
i edit the text if i don't choose the image,which is empty
so,How can i solve the problem ?
Thanks

mlseim 01-05-2013 05:40 PM

Don't let them change the photo image using that particular edit script.
If they need to change the photo, create a separate edit script for that.
Use the script you're showing us for only changing textbox information
such as name and email.

minkoko 01-06-2013 12:55 AM

Quote:

Originally Posted by mlseim (Post 1304263)
Don't let them change the photo image using that particular edit script.
If they need to change the photo, create a separate edit script for that.
Use the script you're showing us for only changing textbox information
such as name and email.

So,when i only edit the photo ,how to recall the photo from the list.php

i call with photo id value like this value="<?php row['photo']; ?>

and i don't get the photo value in edit.php

mlseim 01-06-2013 01:28 AM

Sorry, I don't follow you ...

There is one form to edit the photo.
You show them the photo that is currently there,
and then when they pick a new one from their PC
and submit, the current photo is overwritten by
the new one.

minkoko 01-06-2013 01:44 AM

Quote:

Originally Posted by mlseim (Post 1304363)
Sorry, I don't follow you ...

There is one form to edit the photo.
You show them the photo that is currently there,
and then when they pick a new one from their PC
and submit, the current photo is overwritten by
the new one.

yes, i pick the picture from my pc the photo is overwritten on existinig photo

So, i just edit the name and don't edit photo ,i want to still the photo
last existance photo don't pick the photo again ,
if update the photo is empty or my script is not work if i don't choose the photo
Do you know to solve this?
Thanks for your suggestion

mlseim 01-06-2013 05:15 PM

You can just change the photo filename name if you wish, the filename and not the actual photo.
I just don't know why you would want to do that.

When a photo is uploaded, it puts the photo(s) into a directory somewhere and
the photo filename is written into your database table? I assume that is what you're doing.

So your column name "photo" is the filename of the photo itself.

Is that how you have it set up?


All times are GMT +1. The time now is 06:39 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.