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 7 of 7
  1. #1
    New Coder
    Join Date
    Apr 2010
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Can't display my image path stored in mysql database

    Dear Friends,

    Displaying image path stored in the database. I am successfully displaying other information stored in the database accept the image "Picture"

    I have been trying to solve this for some time without success. I hope i should post on this vibrant forum for kind assistant.

    This is my image upload file:

    //clean vars for mysql use
    $caccno=mysql_real_escape_string($_POST['accno']);
    $cbal=mysql_real_escape_string($_POST['bal']);
    $ctype = $_POST['select'];
    $cname=mysql_real_escape_string($_POST['name']);
    $caddress=mysql_real_escape_string($_POST['address']);
    $cemail=mysql_real_escape_string($_POST['email']);
    $cbusname=mysql_real_escape_string($_POST['busname']);
    $cbusnat=mysql_real_escape_string($_POST['busnat']);
    $cnextkin=mysql_real_escape_string($_POST['nextkin']);
    $cavermon=mysql_real_escape_string($_POST['avermon']);
    $cdate=mysql_real_escape_string($_POST['date']);
    $cpicture=mysql_real_escape_string($_FILES['picture']['name']);
    $csign=mysql_real_escape_string($_FILES['sign']['name']);

    $target = "images/";
    $target = $target . basename( $_FILES['picture']['name']);
    //This gets all the other information from the form
    $picture=($_FILES['picture']['name']);

    //Writes the photo to the server
    if(move_uploaded_file($_FILES['picture']['tmp_name'], $target))
    {
    //Tells you if its all ok
    echo "The file ". basename( $_FILES['picture']['name']). " has been uploaded, and your information has been added to the directory";
    }
    else {
    //Gives and error if its not echo "Sorry, there was a problem uploading your file.";
    }

    This is my display code:

    $res = mysql_query($sql);
    if($res){

    while($row = mysql_fetch_assoc($res)){


    echo ' <tr>
    <td valign="top">'.$row['name'].'</td>
    <td valign="top">'.$row['accno'].'</td>
    <td valign="top">'.$row['busname'].'</td>
    <td valign="top">'.$row['address'].'</td>
    <td valign="top">'.$row['email'].'</td>
    <td valign="top">'.$row['busnat'].'</td>
    <td valign="top">'.$row['nextkin'].'</td>
    <td valign="top">'.$row['avermon'].'</td>
    <td valign="top">'.$row['date'].'</td>
    Picture Code <td valign="top"><img src=?php echo "http://localhost/images/'.$row['picture'] .'?>"alt=”" name=”" width=”100? height=”90? border=”1? </td>
    <td valign="top">'.$row['sign'].'</td>
    <td valign="top">'.$row['pin'].'</td>
    <td valign="top">'.$row['balance'].'</td>
    <td valign="top"><a href="viewaccs.php?id='.$row['cusid'].'">View Accounts</a></td>


    </tr>';
    }
    echo '</table>';

    Your response would be highly appreciated.

  • #2
    New Coder
    Join Date
    Apr 2010
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts
    It also stored successfully in the folder "image"

  • #3
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    what does this comeup with?

    PHP Code:
    <?php

    $res 
    mysql_query($sql); 
    if(
    $res){
        while(
    $row mysql_fetch_assoc($res)){ 
            if( 
    file_exists("http://localhost/images/" $row['picture'] ) ) {
            
    ?>
                <tr> 
                <td valign="top"><?php echo $row['name']; ?></td>
                <td valign="top"><?php echo $row['accno']; ?></td>
                <td valign="top"><?php echo $row['busname']; ?></td> 
                <td valign="top"><?php echo $row['address']; ?></td>
                <td valign="top"><?php echo $row['email']; ?></td>
                <td valign="top"><?php echo $row['busnat']; ?></td>
                <td valign="top"><?php echo $row['nextkin']; ?></td>
                <td valign="top"><?php echo $row['avermon']; ?></td>
                <td valign="top"><?php echo $row['date']; ?></td>
                <td valign="top"><img src="http://localhost/images/<?php echo $row['picture']; ?>" alt="" name="" width="" height="" border="1" /></td>
                <td valign="top"><?php echo $row['sign']; ?></td> 
                <td valign="top"><?php echo $row['pin']; ?></td>
                <td valign="top"><?php echo $row['balance']; ?></td>
                <td valign="top"><a href="viewaccs.php?id=<?php echo $row['cusid']; ?>">View Accounts</a></td> 
                </tr>
             <?php
            
    }else{
                echo 
    "<p>File: http://localhost/images/" $row['picture'] . " does not exist</p>";    
            }
        }

    echo 
    '</table>';

    ?>
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #4
    New Coder
    Join Date
    Apr 2010
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you Jackson,

    I am very very grateful on your effort to assist me solve this.

    When I tried the codes it came up with These:


    File: http://localhost/images/ does not exist

    File: http://localhost/images/ does not exist

    File: http://localhost/images/ does not exist

    File: http://localhost/images/ does not exist

    File: http://localhost/images/photo.jpg does not exist

    File: http://localhost/images/ does not exist

    File: http://localhost/images/daniel jamb.jpg does not exist

    File: http://localhost/images/photo.jpg does not exist

    Thanks

  • #5
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    if (file_exists('./images/'.$row['picture'])) {
    The path may need adjusting to suit.

  • #6
    New Coder
    Join Date
    Apr 2010
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you for response. With the path adjustment i can now view rest of the information from the database. But the picture is still not showing.

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Apply the same to the img tag. Localhost won't work anyhows as soon as you move the code off your local machine, so use relative paths. Again, adjust the path to what it actually is.

    Code:
    <td valign="top"><img src="./images/<?php echo $row['picture']; ?>" alt="" name="" width="" height="" border="1" /></td>


  •  

    Posting Permissions

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