0

I'm using the following code retriever image from DB along with other attributes i.e Full Name, Mobile No. etc.But it is showing an empty image box.

require 'database.php';
$MobileNo = null;
if ( !empty($_GET['MobileNo'])) {
$MobileNo = $_REQUEST['MobileNo'];
}

if ( null==$MobileNo ) {
header("Location: index.php");
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM user where MobileNo = ?";
$q = $pdo->prepare($sql);
$q->execute(array($MobileNo));
$data = $q->fetch(PDO::FETCH_ASSOC);
Database::disconnect();
}
?>
<div class="control-group">
<label class="control-label">Picture</label>
<div class="">
<label class="">
<?php

 $row = $data or die("line 44 not working");
 $s=$row['Picture'];
 echo $row['Picture'];

 echo '<img src="'.$s.'" alt="HTML5 Icon"style="width:128px;height:128px">';
 ?>

 </label>
 </div>
 </div>
3
  • 1
    Database::disconnect(); <<< guess what that does. Commented Mar 13, 2016 at 17:54
  • 2
    Disconnects DB connection Commented Mar 13, 2016 at 18:01
  • There you go ;-) Commented Mar 13, 2016 at 18:10

1 Answer 1

1

You have disconnected the database before fetching $row = $data or die("line 44 not working");

You need to disconnect it after the variable is set.

if ( null==$MobileNo ) {
header("Location: index.php");
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM user where MobileNo = ?";
$q = $pdo->prepare($sql);
$q->execute(array($MobileNo));
$data = $q->fetch(PDO::FETCH_ASSOC);


$row = $data or die("line 44 not working");
 $s=$row['Picture']; //This is where you make the change. 
 echo $row['Picture'];
Database::disconnect(); //Now disconnect
}
?>
<div class="control-group">
<label class="control-label">Picture</label>
<div class="">
<label class="">
<?php



 echo '<img src="'.$s.'" alt="HTML5 Icon"style="width:128px;height:128px">';
 ?>

 </label>
 </div>
 </div>
Sign up to request clarification or add additional context in comments.

2 Comments

Is there any error? Does the other elements of the page show up?
All other elements are working fine..Only image box is empty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.