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 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Thumbs up recall images name in input type[problem]

    i want to edit my database without image

    when i click the edit link ,the image is not show in my browse input type

    this is my code

    db.php
    Code:
    <?php
    $server="localhost";
    $username="root";
    $password="";
    $dbname="zz";
    $connection =mysql_connect($server,$username,$password);
    $db = mysql_select_db($dbname,$connection);
    ?>
    list.php
    Code:
    <?php
    
    require('db.php');
    ?>
    
    <table>
    <tr><td>Id</td><td>Name</td><td>Photo</td><td>Prize</td><td>Edit</td></tr>
    <?php
    $sql = "SELECT * FROM edit";
    $result = mysql_query($sql);
    while($row=mysql_fetch_array($result)){
        ?>
    <tr>
            <td><? echo $row[0]; ?></td>
            <td><? echo $row[1]; ?></td>
            <td><img src="images/<? echo $row[2]; ?>"></td>
            <td><? echo $row[3]; ?></td>
            <td><a href="edit.php?id=<?php echo $row[0]; ?>">Edit</a></td>
    </tr>
      <?php
    }
    
    ?>
    </table>
    edit.php
    Code:
    <html>
        <?php require('db.php'); ?>
        
        <head><title>add</title></head>
        <body>
            <?php
        if(isset($_GET['id'])){
        $id=$_GET['id'];
        $result=mysql_query("SELECT * FROM edit WHERE id='$id'");
        $row=mysql_fetch_assoc($result);
       
        
        ?>
           
            <form action="edit.php" method="post" enctype="multipart/form-data" >
            Name: <input type="text" name="name" value="<?php echo $row['name']; ?>"/><br/>
         
            Photo: <input type="file" name="photo" value="<?php echo $row['photo']; ?> " /><?php echo $row['photo'];?><br/>
            Prize : <input type="text" name="prize" value="<?php echo $row['prize']; ?>"/><br/>
            <input type="hidden" name="hid" value="<?php echo $row['id']; ?>"/>
            <input type="submit" name="insert" value="Insert"/>
            </form>
             <?php
       }
        ?>
             <?php
            if(isset($_POST['insert'])){
                $hid=$_POST['hid'];
                $name=$_POST['name'];
                $photo=$_FILES['photo']['name'];
                $prize = $_POST['prize'];
               
                $query = "UPDATE edit SET name='$name',photo='$photo',prize='$prize' WHERE id='$hid'";
                $result= mysql_query($query);
                 move_uploaded_file($_FILES["photo"]["tmp_name"],"images/" . $_FILES["photo"]["name"]);
                
            }
            ?>
        <body>
    </html>
    problem code
    Code:
    Photo: <input type="file" name="photo" value="<?php echo $row['photo']; ?> " /><?php echo $row['photo'];?><br/>
    I want to show image name in input file value box ,when i edit this file is empty.
    i don't want to edit my photo , i just edit my text
    my problem is when i edit the text and not choose the image ,the image is empty .Anybody know how to solve this problem?
    Thanks for your appreciate.
    Last edited by minkoko; 02-04-2013 at 03:32 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You can't. The file input type is for browsing, you cannot pre-populate it. Its don't think its illegal to provide it with a value (as in, I think the specifications allow the value property on any input including a file type), but best I know every browser rejects it for security reasons. What would stop me from requesting an upload any file I want off of a client machine without showing the actual input for it at all?

    Perhaps what you are wanting is simply the text input type. Since you already appear to have the image and just want to modify data, that would be a text input, not a file input.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts
    Thank for reply Fou-Lu

    Now i can solve this problem
    Code:
    <input type="file" name="photo" value=<?php eco $row['photo']; ?> disable=1>
    and i use change with js

    Big Thank by minkoko


  •  

    Posting Permissions

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