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 05-24-2010, 02:34 PM   PM User | #1
theophilusnwizu
New Coder

 
Join Date: Apr 2010
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
theophilusnwizu is an unknown quantity at this point
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.
theophilusnwizu is offline   Reply With Quote
Old 05-24-2010, 02:36 PM   PM User | #2
theophilusnwizu
New Coder

 
Join Date: Apr 2010
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
theophilusnwizu is an unknown quantity at this point
It also stored successfully in the folder "image"
theophilusnwizu is offline   Reply With Quote
Old 05-24-2010, 03:18 PM   PM User | #3
Phil Jackson
Senior Coder

 
Join Date: Aug 2009
Location: Mansfield, Nottinghamshire, UK
Posts: 1,547
Thanks: 57
Thanked 148 Times in 147 Posts
Phil Jackson is on a distinguished road
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(); 
Phil Jackson is offline   Reply With Quote
Old 05-24-2010, 09:03 PM   PM User | #4
theophilusnwizu
New Coder

 
Join Date: Apr 2010
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
theophilusnwizu is an unknown quantity at this point
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
theophilusnwizu is offline   Reply With Quote
Old 05-24-2010, 09:12 PM   PM User | #5
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
Code:
if (file_exists('./images/'.$row['picture'])) {
The path may need adjusting to suit.
MattF is offline   Reply With Quote
Old 05-24-2010, 10:28 PM   PM User | #6
theophilusnwizu
New Coder

 
Join Date: Apr 2010
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
theophilusnwizu is an unknown quantity at this point
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.
theophilusnwizu is offline   Reply With Quote
Old 05-24-2010, 10:45 PM   PM User | #7
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
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>
MattF 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:55 PM.


Advertisement
Log in to turn off these ads.