Jump to content

Recommended Posts

I'm trying to display an image, its url is stored in database and i assign the url a variable but the image isn't displaying. When I echo the variable I  get

Array

Why does it say Array and doesn't display the image?

<?php
session_start();
?>
<?php require_once('Connections/elvisdb.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_elvisdb, $elvisdb);
$query_Recordset1 = sprintf("SELECT * FROM userinformation WHERE usernm = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $elvisdb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$colname_Recordset2 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset2 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_elvisdb, $elvisdb);
$query_Recordset2 = sprintf("SELECT * FROM images WHERE usnm = %s", GetSQLValueString($colname_Recordset2, "text"));
$Recordset2 = mysql_query($query_Recordset2, $elvisdb) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
$img = $row_Recordset2;
echo $img;
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<p><?php echo $row_Recordset1['why']; ?>
<?php echo $_SESSION['MM_Username']; ?></p>
<p><?php echo $row_Recordset1['album']; ?></p>
<p><?php echo $row_Recordset1['song']; ?></p>
<p><?php echo $row_Recordset2['imageName']; ?></p>
<p><img src="<?php echo $img; ?> "></p>
</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);
?>

Link to comment
https://forums.phpfreaks.com/topic/43390-solved-image-display/
Share on other sites

it says array because your trying to call the whole variable try something along the lines of

 

 

$img = $row_Recordset2['imagedata']; //where imagedata is the column name that stores the image data.

 

also too, i dont see you listing the mime type. Could be why its not displaying.

 

might want to add something like

 

Header( "Content-type: image/jpeg");

Link to comment
https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211075
Share on other sites

Where i got the header i don't get an error but if i move it i do. I got

 <p><?php echo $row_Recordset1['why']; ?>
<?php echo $_SESSION['MM_Username']; ?></p>
<p><?php echo $row_Recordset1['album']; ?></p>
<p><?php echo $row_Recordset1['song']; ?></p>
<p><img src="<?php Header("Content-type: image/jpeg\n\n"); echo '$img'; ?> "></p>

The image still isn't displaying

Link to comment
https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211348
Share on other sites

When i click on properties of where the image is supposed in the webpage i get this for the url-

3EWarning%3C/b%3E:%20%20Cannot%20modify%20header%20information%20-%20headers%20already%20sent%20by%20(output%20started%20at%20C:/Program%20Files/xampp/htdocs/epeople/userpage.php:4)%20in%20%3Cb%3EC:/Program%20Files/xampp/htdocs/epeople/userpage.php%3C/b%3E%20on%20line%20%3Cb%3E71%3C/b%3E%3Cbr%20/%3Euploads/arydt.JPG

 

what does it mean? How can i sort it out?  My code

<?php
session_start();
?>
<?php require_once('Connections/elvisdb.php'); ?>
<?php

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_elvisdb, $elvisdb);
$query_Recordset1 = sprintf("SELECT * FROM userinformation WHERE usernm = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $elvisdb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$colname_Recordset2 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset2 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}

mysql_select_db($database_elvisdb, $elvisdb);
$query_Recordset2 = sprintf("SELECT * FROM images WHERE usnm = %s", GetSQLValueString($colname_Recordset2, "text"));
$Recordset2 = mysql_query($query_Recordset2, $elvisdb) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
$img = $row_Recordset2['imageName'];
echo $img;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<p><?php echo $row_Recordset1['why']; ?>
<?php echo $_SESSION['MM_Username']; ?></p>
<p><?php echo $row_Recordset1['album']; ?></p>
<p><?php echo $row_Recordset1['song']; ?></p>
<p><img src="<?php Header("Content-type: image/JPG, image/gif\n\n"); echo "$img"; ?> "></p>
</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);
?>

Link to comment
https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211595
Share on other sites

Wow dude, what exactly are you trying to do??

 

If you have the filename to display the image should be as simple as this:

 

<p><?php echo $row_Recordset1['why']; ?>
<?php echo $_SESSION['MM_Username']; ?></p>
<p><?php echo $row_Recordset1['album']; ?></p>
<p><?php echo $row_Recordset1['song']; ?></p>
<p><img src="<?php print $img;?>"></p>

 

That should work. No need to send headers unless you are creating an image on the fly with GD Library.

Link to comment
https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211701
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.