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 01-05-2013, 11:20 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
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
__________________
Quote:
Myanmar Web Developer & Designer
http://www.cyberoot.com
minkoko is offline   Reply With Quote
Old 01-05-2013, 05:40 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Old 01-06-2013, 12:55 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
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
__________________
Quote:
Myanmar Web Developer & Designer
http://www.cyberoot.com
minkoko is offline   Reply With Quote
Old 01-06-2013, 01:28 AM   PM User | #4
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Old 01-06-2013, 01:44 AM   PM User | #5
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
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
__________________
Quote:
Myanmar Web Developer & Designer
http://www.cyberoot.com
minkoko is offline   Reply With Quote
Old 01-06-2013, 05:15 PM   PM User | #6
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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?
mlseim 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 05:04 PM.


Advertisement
Log in to turn off these ads.