Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-04-2013, 03:27 AM   PM User | #1
minkoko
New Coder

 
Join Date: Aug 2010
Location: myeik
Posts: 72
Thanks: 4
Thanked 5 Times in 5 Posts
minkoko can only hope to improve
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.
__________________
Quote:
Myanmar Web Developer & Designer
http://www.cyberoot.com

Last edited by minkoko; 02-04-2013 at 03:32 AM..
minkoko is offline   Reply With Quote
Old 02-04-2013, 05:26 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-06-2013, 11:17 AM   PM User | #3
minkoko
New Coder

 
Join Date: Aug 2010
Location: myeik
Posts: 72
Thanks: 4
Thanked 5 Times in 5 Posts
minkoko can only hope to improve
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
__________________
Quote:
Myanmar Web Developer & Designer
http://www.cyberoot.com
minkoko is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:41 AM.


Advertisement
Log in to turn off these ads.