Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Exclamation 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

  2. #2
    Supreme Master coder!
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    10,188
    Thanks
    10
    Thanked 1,166 Times in 1,157 Posts
    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.

  3. #3
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by mlseim View Post
    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

  4. #4
    Supreme Master coder!
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    10,188
    Thanks
    10
    Thanked 1,166 Times in 1,157 Posts
    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.

  5. #5
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by mlseim View Post
    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

  6. #6
    Supreme Master coder!
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    10,188
    Thanks
    10
    Thanked 1,166 Times in 1,157 Posts
    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?


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •