Sir, I am using these codes

<?php
require_once("connect.php");

if(isset($_POST ['display']))
{
    $sql="select * from photo where id=2 ";
    $query=mysqli_query($con,$sql);
    while($row=mysqli_fetch_array($query))
    {
    $image=$row ['picture'];
    echo '<img src="upload/'.$image.'" width="50" height="50">';
    }
}

?> 

<html>
<head>
<style type="text/css">

html {
overflow:auto;
}

body{
background-color:#e7f4fe;
}

#container {
margin: auto;
position:absolute;
top:0;left:0;right:0;bottom:0;
background-color:#CFC;
padding:10px;
overflow:auto;
width:200px;
height:200px;
border:1px solid #6CF;
text-align:center;
}
</style>

</head>

 <body>
 <div id="container">
   <form action="" method="post"
 enctype="multipart/form-data">
     <img id="photo" width="100" height="100" src="photo96.png" style="text-align: center;" /><br />
     <br>
     <input type="submit"  name="display" value="Display">
   </form>
 </div>
 </body>

 </html>

It work fine, but when I press display button then image from table is shown in top left corner of the screen but i want to display it in div like this:

[IMG]http://i39.tinypic.com/2yyo02f.jpg[/IMG]

Recommended Answers

All 6 Replies

Are you attempting to replace the existing picture or place the new picture next to it?

Yes I am trying to replace the existing picture.

Ok, then leverage your existing if statement, add an else block. Assign the appropriate value to $image depending on whether its true or false. If false, assign photo96.png as the value.

Then on line 49 use this variable for the source. That way, you have one image element but you assign the correct source depending on whether the if..else is True or False. You won't need line 11.

Thanks, you mean I should use folloiwng codes in line 49

<?php echo '<img src="upload/'.$image.'" width="50" height="50">'; ?>

then how to show photo96.png as existing image?
Do not know how to use If...else block in above codes.

Please help again

Something like this...

 if(isset($_POST ['display']))
 {
    $sql="select * from photo where id=2 ";
    ...
    $image=$row ['picture'];
    $image="upload/" . $image;
 }
 else
 {
    $image="photo96.png"
 }

Then in your HTML...simply echo $image where the source attribute is located.

Thanks sir,

It works fine now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.