garydt Posted March 19, 2007 Share Posted March 19, 2007 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/43390-solved-image-display/ Share on other sites More sharing options...
garydt Posted March 20, 2007 Author Share Posted March 20, 2007 Can anyone say what i'm doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211070 Share on other sites More sharing options...
pcbytes Posted March 20, 2007 Share Posted March 20, 2007 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"); Quote Link to comment https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211075 Share on other sites More sharing options...
garydt Posted March 20, 2007 Author Share Posted March 20, 2007 Thanks for that. The first bit works but now getting Cannot modify header information I have read the 'header errors' topic and i've tried Header("Content-type: image/jpg"); virtually everywhere in the code but no luck. where should it go? Quote Link to comment https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211164 Share on other sites More sharing options...
garydt Posted March 20, 2007 Author Share Posted March 20, 2007 I think i've placed the header in the right place <p><img src="<?php Header("Content-type: image/jpeg\n\n"); echo $img; ?> "></p> but the image isn't displaying Quote Link to comment https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211336 Share on other sites More sharing options...
per1os Posted March 20, 2007 Share Posted March 20, 2007 Make sure the header(""); is called BEFORE any output is done. IE: <?php Header("Content-type: image/jpg"); // should work but if print "bob"; Header("Content-type: image/jpg");// will throw an error due to "bob" being outputted. ?> Quote Link to comment https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211340 Share on other sites More sharing options...
garydt Posted March 20, 2007 Author Share Posted March 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211348 Share on other sites More sharing options...
garydt Posted March 20, 2007 Author Share Posted March 20, 2007 Has anyone got any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211438 Share on other sites More sharing options...
garydt Posted March 20, 2007 Author Share Posted March 20, 2007 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211595 Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211701 Share on other sites More sharing options...
garydt Posted March 21, 2007 Author Share Posted March 21, 2007 Thanks very much! Quote Link to comment https://forums.phpfreaks.com/topic/43390-solved-image-display/#findComment-211916 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.