View Single Post
Old 09-18-2012, 07:53 AM   PM User | #1
gazaian1
New Coder

 
Join Date: Aug 2011
Posts: 52
Thanks: 24
Thanked 0 Times in 0 Posts
gazaian1 is an unknown quantity at this point
Question How to display image from a database

i have a script i wrote that uploads an image to the database then moves it to a directory leaving only image path in the database but when i try to display the image i does not show any help appreciated. Thanks

Upload script
PHP Code:
if(isset($_POST['subbutton'])){

$name $_POST['namet'];
$email $_POST['emailt'];
$about $_POST['about'];
$location $_POST['locationt'];
$website $_POST['websitet'];
$comment $_POST['commentt'];

        
$uploadDir 'wp-content/themes/speedy/testimonial/'//Image Upload Folder
        
        
$allowed_ext =  array('jpg''jpeg''png''gif');
        
        
$fileName addslashes($_FILES['pict']['name']);
        
$tmpName  $_FILES['pict']['tmp_name'];
        
$fileSize $_FILES['pict']['size'];
        
$fileType $_FILES['pict']['type'];
        
$file_ext strtolower(end(explode('.'$fileName)));
        
$filePath addslashes($uploadDir $fileName);
        
$result move_uploaded_file($tmpName$filePath);

if (
in_array($file_ext$allowed_ext) === false){

}        
if(
$name!="" && $email!="" && $comment!=""){
    
$query="INSERT INTO testimonial(id, name, email, about, location, website, picture, comment)
              VALUES ('', '$name', '$email', '$about', '$location', '$website', '$filePath', '$comment')"
;
              
mysql_query($query)  or die(mysql_error());
              echo 
"<br/><b style='color:green'>Your testimonial has been received</b>";
}else{
  echo 
"<br/><b style='color:red;'>there was an error.</b>";
}
  
$to "dianreidreid@gmail.com";
$subject "Testimonial approval request";
$name $_POST['namet'];
$email $_POST['emailt'];
$comment $_POST['commentt'];
$message "
Name: $name $email<br/>
Email: $email_field<br/>
Message: $comment"
;
$headers  'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
// Additional headers
/*$headers .= 'To: <[email address goes here]>' . "\r\n";
$headers .= '[From] <[email address goes here]>' . "\r\n";*/
// Mail it
mail($to$subject$message$headers);    
  

This is how i try to display the image
PHP Code:
 $per_page = 4;

                        $pages_query = mysql_query("SELECT COUNT(id) FROM testimonial")or die(mysql_error());
                        $pages = ceil(mysql_result($pages_query, 0) / $per_page);

                        $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
                        $start = ($page - 1) * $per_page;
                        
                        $query = mysql_query("SELECT name, comment, picture FROM testimonial LIMIT $start, $per_page ");
                        $count=mysql_num_rows($query);
                        
                        $pic=file_exists($query_row['picture']);
                        
                        $count=1;
                        while ($query_row = mysql_fetch_array($query)){
                        ?>
                        
                      <?php if($count==1){ ?>
                        <div class="testmon_box">
                      <?php ?>
                      <?php if($count<=1){ ?>    
                      <div class="TESMON_INNERBOX">
                       
                         
                                
                     [COLOR="Blue"] <div class="pic_block">
                            <?php if($pic !=""){?>
                                <img src="<?php echo $pic?>" />
                            <?php } else{?><img src="<?php bloginfo('template_url'); ?>/images/pic_02.jpg" /><?php ?>
                            
                      </div>[/COLOR]
                        
                       <div class="test_cont_block">

                          <p> <?php echo $result=$query_row['comment']; ?></p>

                         <span class="danam"> 
                        Date of Posting: <?php echo date('l, F j, Y'); ?><br/>

                        <strong>Posted by: <?php echo $result=$query_row['name']; ?></strong>

                         </span>
                         
                       </div>
                            
                             
                             
                       <div class="clear"> </div>

                        </div>

                    

                        </div>
                       <?php ?>
                              
                       <?php ?>
                     
                      <div class="pagin_nav">
                         <?php if ($pages >=&& $page <= $pages){
                           for (
$x=1$x<=$pages$x++){
                                echo (
$x == $page) ? '<strong><a href="?page='.$x.'">'.$x.'</a></srtong> ' '<a href="?page='.$x.'">'.$x.'</a> ';
                              
                           }
                         }
?>
gazaian1 is offline   Reply With Quote