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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    116
    Thanks
    19
    Thanked 1 Time in 1 Post

    Image Wrong Position

    Sir I am using these codes

    PHP Code:
    <?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:


  • #2
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    408
    Thanks
    2
    Thanked 32 Times in 32 Posts
    It is doing that because you are generating the image tag before you generate the rest of the page.

    Remove this:
    echo '<img src="upload/'.$image.'" width="50" height="50">';
    From the scripting at the top of the page

    And then insert this:
    <?php echo '<img src="upload/'.$image.'" width="50" height="50">'; ?>

    At the place in the code where you want the image.
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&

  • #3
    Regular Coder
    Join Date
    Oct 2011
    Posts
    116
    Thanks
    19
    Thanked 1 Time in 1 Post
    Thanks for helping but how to show existing picture (src="photo96.png") when form loads.

    Actually I am trying to replace existing picture.

  • #4
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    408
    Thanks
    2
    Thanked 32 Times in 32 Posts
    just set the scr to the image that you want to show on load.

    Are you trying to do some kind of swap? If so you will need to do it client side with javascript. The server can only apply one image before it sends to the browser. The client cannot execute PHP, and does not even see that code.
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&


  •  

    Posting Permissions

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