Hi, I cant change the header to display images from a database. It's giving me this error :
Warning: Cannot modify header information - headers already sent by (output started at /home/content/d/f/m/dfmcons/html/secwhouse/index.php:18) in /home/content/d/f/m/dfmcons/html/secwhouse/index.php on line 71
Here is the code :
[php]
<?
mysql_connect("$host","$username", "$password");
mysql_select_db("secwhouse");
?>
<head>
<title>Security Warehouse Sample Concept</title>
</head>
<body>
<table width="750" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<th scope="col"><table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/
shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="750" height="125">
<param name="movie" value="secbanner2.swf" />
<param name="quality" value="high" />
<embed src="secbanner2.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="750" height="125"></embed>
</object></th>
</tr>
</table>
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><form id="mnusrch" name="mnusrch" method="post" action="">
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><input type="text" name="textfield" /></th>
<th scope="col"><img src="images/sec_01.gif" width="72" height="30" /></th>
<th scope="col"><img src="images/sec_03.gif" width="359" height="30" /></th>
<th scope="col"><img src="images/sec_04.gif" width="74" height="30" /></th>
<th scope="col"><img src="images/sec_05.gif" width="98" height="30" /></th>
</tr>
</table>
</form>
</th>
</tr>
</table>
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><img src="images/menu_01.gif" width="91" height="14" /></th>
<th scope="col"><img src="images/menu_02.gif" width="92" height="14" /></th>
<th scope="col"><img src="images/menu_03.gif" width="104" height="14" /></th>
<th scope="col"><img src="images/menu_04.gif" width="110" height="14" /></th>
<th scope="col"><img src="images/menu_05.gif" width="91" height="14" /></th>
<th scope="col"><img src="images/menu_06.gif" width="105" height="14" /></th>
<th scope="col"><img src="images/menu_07.gif" width="157" height="14" /></th>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"> </th>
</tr>
</table>
<?
$sql = "SELECT * FROM `prod` WHERE `prod`.`special` = 'n'";
$counter=0;
$result =mysql_query($sql);
while($rows=mysql_fetch_array($result))
{
$count=0;
while($count<>5)
{
?>
<table border="0" cellspacing="0" cellpadding="0" id="main">
<tr>
<th scope="col"><table border="0" cellpadding="0" cellspacing="0" id="left1">
<tr>
<th scope="col"><? header("Content-type: image/jpeg");echo $rows['image']; ?></th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"><? echo $rows['prod']; ?></th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"><? echo $rows['price']; ?></th>
</tr>
</table></th>
<th scope="col"> </th>
<th scope="col"><table border="0" cellspacing="0" cellpadding="0">
<tr>
<?
$rows=mysql_fetch_array($result);
?>
<th scope="col"><? echo $rows['image']; ?></th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"><? echo $rows['prod']; ?></th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"><? echo $rows['price']; ?></th>
</tr>
</table></th>
<th scope="col"> </th>
<th scope="col"><table border="0" cellpadding="0" cellspacing="0" id="right1">
<tr>
<th scope="col"> </th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
</table></th><? $count=5 ?>
</tr>
</table><? } }?>
<br />
<p> </p>
<p><br />
</p>
<p> </p>
<p> </p>
<p> </p></th>
</tr>
</table>
</body>
</html>
[/php]I left out the connection details, cos the password is visible That is not the only thing you left out. You must enclose all code within the appropriate code tags. Read the Posting Guidelines. - moderator 22 2015
Post your code again after masking the password, and applying [php] tags.
Now you have disordered line 18 and 71, the actual culprits.
Hi,
The headers have to be set before any output is given. Output includes blank lines in the file. you can process information before the headers are set you just can't write anything to the screen.
Perhaps that's the problem.
Cheers
nathj
I cant Even see any headers being sent =/
I cant Even see any headers being sent =/
Nor can I but I'm guessing there something in the code that was left out.
Perhaps you could post the full code sample, using tags, but simply change the sesitive data to indicate what shuold be there.
nathj
Surely line 66 - header("Content-type: image/jpeg");
is your error...
Surely line 66 - header("Content-type: image/jpeg");
is your error...
Indeed it is. :D
Can't believe i missed that :(
Ohwell, move that line to the beggining of your script.
Indeed it is. :D
Can't believe i missed that :(
Ohwell, move that line to the beggining of your script.
NO!!! Its not an image file!
Instead of <? header("Content-type: image/jpeg");echo $rows['image']; ?>, write <img src="<?php echo $rows['image']; ?>"></img>
*If $rows['image'] referrers to the name of the image file.
NO!!! Its not an image file!
Instead of <? header("Content-type: image/jpeg");echo $rows['image']; ?>, write <img src="<?php echo $rows['image']; ?>"></img>
Calm down.
I was tired last night _
Calm down.
I was tired last night _
I'm calm :)
And the OP isn't back!
[PHP]<?
$host="******";
$username="******";
$password="*******";
$dbname="secwhouse";
mysql_connect("$host","$username", "$password");
mysql_select_db("$dbname");
header("Content-type: image/jpeg");
?>[/PHP[HTML]]<head>
<title>Security Warehouse Sample Concept</title>
</head>
<body>
<table width="750" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<th scope="col"><table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="750" height="125">
<param name="movie" value="secbanner2.swf" />
<param name="quality" value="high" />
<embed src="secbanner2.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="750" height="125"></embed>
</object></th>
</tr>
</table>
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><form id="mnusrch" name="mnusrch" method="post" action="">
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><input type="text" name="textfield" /></th>
<th scope="col"><img src="images/sec_01.gif" width="72" height="30" /></th>
<th scope="col"><img src="images/sec_03.gif" width="359" height="30" /></th>
<th scope="col"><img src="images/sec_04.gif" width="74" height="30" /></th>
<th scope="col"><img src="images/sec_05.gif" width="98" height="30" /></th>
</tr>
</table>
</form>
</th>
</tr>
</table>
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><img src="images/menu_01.gif" width="91" height="14" /></th>
<th scope="col"><img src="images/menu_02.gif" width="92" height="14" /></th>
<th scope="col"><img src="images/menu_03.gif" width="104" height="14" /></th>
<th scope="col"><img src="images/menu_04.gif" width="110" height="14" /></th>
<th scope="col"><img src="images/menu_05.gif" width="91" height="14" /></th>
<th scope="col"><img src="images/menu_06.gif" width="105" height="14" /></th>
<th scope="col"><img src="images/menu_07.gif" width="157" height="14" /></th>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"> </th>
</tr>
</table>[/HTML] [PHP] <?
$sql = "SELECT * FROM `prod` WHERE `prod`.`special` = 'n'";
$counter=0;
$result =mysql_query($sql);
while($rows=mysql_fetch_array($result))
{
$count=0;
while($count<>5)
{
?>[/PHP] [HTML] <table border="0" cellspacing="0" cellpadding="0" id="main">
<tr>
<th scope="col"><table border="0" cellpadding="0" cellspacing="0" id="left1">
<tr>
<th scope="col">[/HTML[PHP]]<? echo $rows['image']; ?>[/PHP[HTML]]</th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row">[/HTML[PHP]]<? echo $rows['prod']; ?>[/PHP][HTML]</th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row">[/HTML][PHP]<? echo $rows['price']; ?>[/PHP][HTML]</th>
</tr>
</table></th>
<th scope="col"> </th>
<th scope="col"><table border="0" cellspacing="0" cellpadding="0">
<tr>[/HTML]
[PHP]<?
$rows=mysql_fetch_array($result);
?>[/PHP][HTML] <th scope="col">[/HTML][PHP]<? echo $rows['image']; ?>[/PHP][HTML]</th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row">[/HTML][PHP]<? echo $rows['prod']; ?>[/PHP][HTML]</th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row">[/HTML][PHP]<? echo $rows['price']; ?>[/PHP][HTML]</th>
</tr>
</table></th>
<th scope="col"> </th>
<th scope="col"><table border="0" cellpadding="0" cellspacing="0" id="right1">
<tr>
<th scope="col"> </th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
</table></th>[/HTML][PHP]<? $count=5 ?>[/PHP]
[HTML]</tr>
</table>[/HTML][PHP]<? } }?>[/PHP]
[HTML] <br />
<p> </p>
<p><br />
</p>
<p> </p>
<p> </p>
<p> </p></th>
</tr>
</table>
</body>
</html>[/HTML] THANKS FOR ALL THE REPLIES, I MOVED THE HEADER CODE TO THE BEGINNING OF THE SCRIPT, THE ERROR IS GONE BUT THE IMAGE DOESN'T DISPLAY , IT JUST SHOWS FUNNY CHARACTERS!!!!!
[php]<?
$host="******";
$username="******";
$password="*******";
$dbname="secwhouse";
mysql_connect("$host","$username", "$password");
mysql_select_db("$dbname");
header("Content-type: image/jpeg");
?><head>
<title>Security Warehouse Sample Concept</title>
</head>
<body>
<table width="750" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<th scope="col"><table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/
cabs/flash/swflash.cab#version=7,0,19,0" width="750" height="125">
<param name="movie" value="secbanner2.swf" />
<param name="quality" value="high" />
<embed src="secbanner2.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="750" height="125"></embed>
</object></th>
</tr>
</table>
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><form id="mnusrch" name="mnusrch" method="post" action="">
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><input type="text" name="textfield" /></th>
<th scope="col"><img src="images/sec_01.gif" width="72" height="30" /></th>
<th scope="col"><img src="images/sec_03.gif" width="359" height="30" /></th>
<th scope="col"><img src="images/sec_04.gif" width="74" height="30" /></th>
<th scope="col"><img src="images/sec_05.gif" width="98" height="30" /></th>
</tr>
</table>
</form>
</th>
</tr>
</table>
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><img src="images/menu_01.gif" width="91" height="14" /></th>
<th scope="col"><img src="images/menu_02.gif" width="92" height="14" /></th>
<th scope="col"><img src="images/menu_03.gif" width="104" height="14" /></th>
<th scope="col"><img src="images/menu_04.gif" width="110" height="14" /></th>
<th scope="col"><img src="images/menu_05.gif" width="91" height="14" /></th>
<th scope="col"><img src="images/menu_06.gif" width="105" height="14" /></th>
<th scope="col"><img src="images/menu_07.gif" width="157" height="14" /></th>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"> </th>
</tr>
</table>
<?
$sql = "SELECT * FROM `prod` WHERE `prod`.`special` = 'n'";
$counter=0;
$result =mysql_query($sql);
while($rows=mysql_fetch_array($result))
{
$count=0;
while($count<>5)
{
?>
<table border="0" cellspacing="0" cellpadding="0" id="main">
<tr>
<th scope="col"><table border="0" cellpadding="0" cellspacing="0" id="left1">
<tr>
<th scope="col"><? echo $rows['image']; ?></th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"><? echo $rows['prod']; ?></th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"><? echo $rows['price']; ?></th>
</tr>
</table></th>
<th scope="col"> </th>
<th scope="col"><table border="0" cellspacing="0" cellpadding="0">
<tr>
<?
$rows=mysql_fetch_array($result);
?>
<th scope="col"><? echo $rows['image']; ?></th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"><? echo $rows['prod']; ?></th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"><? echo $rows['price']; ?></th>
</tr>
</table></th>
<th scope="col"> </th>
<th scope="col"><table border="0" cellpadding="0" cellspacing="0" id="right1">
<tr>
<th scope="col"> </th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
</table></th><? $count=5 ?>
</tr>
</table><? } }?>
<br />
<p> </p>
<p><br />
</p>
<p> </p>
<p> </p>
<p> </p></th>
</tr>
</table>
</body>
</html>[/php]
I moved the header code to the beginning of the script , the error is gone but it doesn't display the image, it just displays funny characters! please help,
Look at post #8
And dont type in caps.
Don't overdo you tags now. Just one pair at start and end of your code suffices.
moderator
I tried that, its displaying a picture box with a red x in it and the funny characters next to it ?
I tried that, its displaying a picture box with a red x in it and the funny characters next to it ?
If the data has the path to the image in it and this is where the image then is it should show just fine. Perhaps the image isn't wwhere the database says it is?
Did you place any alt text in the image text? This should display if the image can't be found.
Double check the file path of the image and check this path in relation to the path of the code being executed.
If you are just using jpg and <img> tags then the header is not strictly necessary as far as I am aware.
Cheers
nathj
I tried that, its displaying a picture box with a red x in it and the funny characters next to it ?
What were you actually trying to get by using that header?..
Also post the HTML generated by that part of the code here.
[HTML]O;k2:S
8 |}y 5
{w,0p?>Ϋq$XQ|oex
kk`y(_ \{N]_p䂦&
/'Z
=f C}oӈiYv
a)a)a)a)a)a)a)a)a)a
)a)a)a)a+ؔ9g,I<s
S>5LonN=RS
=Q=QN9-%.8K2
R㌔%.8K2R
%.8K2R㌔%.8K2W
]du^?t::*ʊ*y5G ,
R,RKn.Ժ%.K2R
댔%.
K2R댔%.K2R댔%.
K2Q{C%F=MyD
>}8ưuRÈRÈRÈRÈW~2h
&2h&2h&2h&2h
&2h&2h&2h&v
*7\R,;rhrE,K
.2RˌҾrd}J_qE)}
Md)}J_qd}J_q
d)}J_qd9;PyTW
qKpSV˖)iJZq9Є
v3 h=v{ 3ݡ!gB=v
3ݡ!gB=v3 sqy
?N1 "> [/HTML]
I have a mysql database to which I uploaded an image not a the path to an image but the actual image. When using a test.php file to display it displays the image fine. It gave me the same error when I used a function.php with the connection string, so I deleted it and put the connection string in the actual page and it worked. But now on the actual page I need to use it , it doesnt want to display?
meant put the connection string in the test page, sorry
Why not just have the path to the image stored in the database and then use that information in a normal <img> tag?
This would be much simpler and not require headers.
Cheers
nathj
For that you would need to make another PHP file. Say get_image.php with the following code:[php]<php
if (!isset($_GET['id'])) die('Invalid Parameter');
/*
DO - CONNECT TO DATABASE
FETCH ARRAY FROM THE DB, WHERE unique_id_of_the_table = $_GET['id']
*/
header("Content-type: image/jpeg");
echo $rows['image'];
?>[/php]
And edit line no. 71 of your above file like this:
[html]<th scope="col"><img src="get_image.php?id=<? echo $rows['unique_id_of_the_table']; ?>"></img></th>[/html]
* unique_id_of_the_table : whatever unique id you are using.
Maybe I'm missing something, and I'm perfectly happy to admit that, but is the point of putting the image itself into the database? Surely it is easier to just put the image as a file on the server somewhere and then put the file path in the database. This can then be used in a nomal <img> tag without any need for faffing around with headers.
It just seems to make more sense to me that way. Obviously you can't set the src of the img to be the actual image which is why it didn't work earlier.
If it were me I would have fields in the table called image_src, image_title and image_alt. Then assuming the SQL had been run and the following code is inside a foreach loop:
[php]
echo "<img src='" . $laRow['image_src'] . "' title='" . $laRow['image_title'] . "' alt='" . $laRow['image_alt'] ."' />' ;
[/php]
I am aware that this is a small code snippet, I would have this in a foreach loop after the SQL returned an associative array. I use this type of structure a lot and it works everytime.
Cheers
nathj
Sign in to post your reply or Sign up for a free account.
Similar topics
by: None |
last post by:
Hello, I am a total newbie to PHP and programming in general. I am playing
around with a PHP / MySQL shopping cart script which I found at...
|
by: Greg Scharlemann |
last post by:
Does the redirect statement:
header(Location:"http://www.newpage.com");
need to come before certain statements?
I've setup a login page and try to redirect a user once they have
logged in...
|
by: lawrence k |
last post by:
How can I find out where my script is outputting to the screen for the
first time?
My error logs are full of stuff like this:
PHP Warning: session_start(): Cannot send
session cache...
|
by: kempy535 |
last post by:
Hi I get this error code when I try to run my login script.
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\Rising...
|
by: nasse |
last post by:
I am getting the following error msg whenever I try to login. I tried to turn my output_buffering = On in my php.ini but is not working for me. Would you please help me:
Warning: Cannot modify...
|
by: mcserret |
last post by:
I know this is a recurring problem that has been addressed here
before, but even after reading all that has gone before, I am still
stumped.
I have a form that is designed to send data to a PHP...
|
by: smartic |
last post by:
I'm having problem with header redirection that is my code:
<?php
header("location:Redirecting.php");
exit;
?>
//Then the HTML
It give me an error
|
by: mrosado |
last post by:
Hi everybody,
I have this problem.-
The browser launch this two errors:
Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at...
|
by: gubbachchi |
last post by:
Hi,
I have written php code to retrive the image from mysql and display it on the webpage. Here is the code
<?php
require_once("DBConnect.php");
$gotten = @mysql_query("select user_photo from...
|
by: jessica87 |
last post by:
hi there, i m using this coding to retrieve the file from database so that my user can download the file...
<?php
if (!isset($_GET)) die('Invalid Parameter');
include...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |