0

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]

2
Contributors
6
Replies
21
Views
3 Years
Discussion Span
Last Post by tqmd1
0

Yes I am trying to replace the existing picture.

0

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.

0

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

1

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.