Hacan Champ
Hacan Champ

Reputation: 53

retriving image from from database through mysqli using php is not working

i am trying to upload and retrieving image from mysql in php. the upload part is working fine while when i am trying to retrieve a image it giving me error. i have try different logic's but i think i am not doing the write one :(. connection.php

<?php
$servername = "localhost";
$username = "root";
$pass = "";
$dbname = "hightech"; 
// Create connection
$conn = new mysqli($servername, $username, $pass, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

uploading

//file upload start
    $file_result="";

        if ($_FILES["add_img"]["error"]>0){
            $file_result .= "No File uploaded or invalid File";
            $file_result .="Error Code: " . $_FILES["sound_input"]["error"] ."<br>";  
        }  
        else {

            move_uploaded_file($_FILES["add_img"]["tmp_name"],
                    "C:/wamp/www/hightech/images/uploads/" 
                    . $_FILES["add_img"]["name"]);
            $file_result .= "File upload Successful!" ;        
        }
        echo $file_result;

        //file upload end

saving file name other data on database

$sql = "INSERT INTO desktop(type,name,company,item_img,price,point1,point2,point3,point4,point5)
        VALUES ('$type','$itemname','$comp','$img','$price','$point1','$point2','$point3','$point4','$point5')";
$run=  $conn->query($sql);

retrieving image and other data from data base.

 <?php             
   $sql1="SELECTname,price,point1,point2,point3,
   point4,point5,item_img       
   FROM desktop WHERE company = 'Alienware' ";
    $sel_query1= mysqli_query($conn, $sql1);
        if($sel_query1 == FALSE) { 
        die(mysqli_error()); // TODO: better error handling
        }

    while ($row = mysqli_fetch_array($sel_query1)) {
        echo'<div>'.
           '<img src="C:/wamp/www/hightech/images/uploads/'.row['item_img']. '"/>'.
           '<span>'.
             '<ul>'.
                '<li  id="item_name" style="color:red">'.$row['name'].'</li>'.
                '<li>'.$row['point1'].'</li>'.
                '<li>'.$row['point2'].'</li>'.
                '<li>'.$row['point3'].'</li>'.
                '<li>'.$row['point4'].'</li>'.
                '<li>'.$row['point5'].'</li>'.
            '<ol style="color:red;padding-left:1;font-size:18">'.$row['price'].'</ol>'.
            '<ol style="padding-left:110"> <a>'.'<img src="http://localhost/hightech/images/add.png" />'. '</a></ol>
             </ul>
          </span>

       </div>';
    }
?>

ERROR: Parse error: syntax error, unexpected '[', expecting ',' or ';' in C:\wamp\www\hightech\admin\admin_desktop.php on line 85

Line 85 is

<img src="C:/wamp/www/hightech/images/uploads/'.row['item_img']. '"/>

Upvotes: 1

Views: 1272

Answers (3)

PHP dev
PHP dev

Reputation: 420

You just try the below code.

  <?php
       $sql1="SELECT fields_you want FROM `tablename` WHERE YOUR_CONDITION ";
       $sel_query1= mysqli_query($conn, $sql1);
        if($sel_query1 == FALSE) 
        { 
          die(mysqli_error()); // TODO: better error handling
        }

      while ($row = mysqli_fetch_array($sel_query1)) 
      {
        echo'<div>'.
       '<img src="images/uploads/'.$row['IMAGE_FIEDL_NAME']."/>'.'</div>';        
      }
  ?>

You just ignore your whole path.If your "images" and "uploads" folder is in the same directory of your project,you just give your path detail like "images/uploads". You can use this folder structure for your uploading process also. It's enough. It will display your images.I tried it.It's working!! You try and let me know.

Upvotes: 1

mercury
mercury

Reputation: 2755

Use dot Before single quote in your sql statement like "'".$type."'", if the problem is in the sql may be it will resolve your problem

Upvotes: 0

Tom-Oliver Heidel
Tom-Oliver Heidel

Reputation: 1131

At $sql1 you missed a space SELECT name. Maybe this is your error since we do not know your error...

And You missed a .$row ['item_img']

Edit. There is also a space on the same line after the bracket.

I am not sure but aren't there some dots missing at the end of echo part?

Upvotes: 0

Related Questions