473,803 Members | 3,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Warning: Cannot modify header information

6 New Member
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","$userna me", "$password" );
mysql_select_db ("secwhouse" );
?>
<head>
<title>Securi ty Warehouse Sample Concept</title>
</head>
<body>
<table width="750" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<th scope="col"><ta ble width="750" border="0" cellspacing="0" cellpadding="0" >
<tr>
<th scope="col"><ob ject classid="clsid: D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macrom edia.com/pub/
shockwave/cabs/flash/swflash.cab#ver sion=7,0,19,0" width="750" height="125">
<param name="movie" value="secbanne r2.swf" />
<param name="quality" value="high" />
<embed src="secbanner2 .swf" quality="high" pluginspage="ht tp://www.macromedia. com/go/getflashplayer" type="applicati on/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"><fo rm id="mnusrch" name="mnusrch" method="post" action="">
<table width="750" border="0" cellspacing="0" cellpadding="0" >
<tr>
<th scope="col"><in put type="text" name="textfield " /></th>
<th scope="col"><im g src="images/sec_01.gif" width="72" height="30" /></th>
<th scope="col"><im g src="images/sec_03.gif" width="359" height="30" /></th>
<th scope="col"><im g src="images/sec_04.gif" width="74" height="30" /></th>
<th scope="col"><im g 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"><im g src="images/menu_01.gif" width="91" height="14" /></th>
<th scope="col"><im g src="images/menu_02.gif" width="92" height="14" /></th>
<th scope="col"><im g src="images/menu_03.gif" width="104" height="14" /></th>
<th scope="col"><im g src="images/menu_04.gif" width="110" height="14" /></th>
<th scope="col"><im g src="images/menu_05.gif" width="91" height="14" /></th>
<th scope="col"><im g src="images/menu_06.gif" width="105" height="14" /></th>
<th scope="col"><im g src="images/menu_07.gif" width="157" height="14" /></th>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<th scope="col">&nb sp;</th>
</tr>
</table>
<?
$sql = "SELECT * FROM `prod` WHERE `prod`.`special ` = 'n'";
$counter=0;
$result =mysql_query($s ql);
while($rows=mys ql_fetch_array( $result))
{
$count=0;
while($count<>5 )
{
?>
<table border="0" cellspacing="0" cellpadding="0" id="main">
<tr>
<th scope="col"><ta ble 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">&nb sp;</th>
</tr>
<tr>
<th scope="row"><? echo $rows['prod']; ?></th>
</tr>
<tr>
<th scope="row">&nb sp;</th>
</tr>
<tr>
<th scope="row"><? echo $rows['price']; ?></th>
</tr>
</table></th>
<th scope="col">&nb sp;</th>
<th scope="col"><ta ble border="0" cellspacing="0" cellpadding="0" >
<tr>
<?
$rows=mysql_fet ch_array($resul t);
?>
<th scope="col"><? echo $rows['image']; ?></th>
</tr>
<tr>
<th scope="row">&nb sp;</th>
</tr>
<tr>
<th scope="row"><? echo $rows['prod']; ?></th>
</tr>
<tr>
<th scope="row">&nb sp;</th>
</tr>
<tr>
<th scope="row"><? echo $rows['price']; ?></th>
</tr>
</table></th>
<th scope="col">&nb sp;</th>
<th scope="col"><ta ble border="0" cellpadding="0" cellspacing="0" id="right1">
<tr>
<th scope="col">&nb sp;</th>
</tr>
<tr>
<th scope="row">&nb sp;</th>
</tr>
<tr>
<th scope="row">&nb sp;</th>
</tr>
<tr>
<th scope="row">&nb sp;</th>
</tr>
<tr>
<th scope="row">&nb sp;</th>
</tr>
</table></th><? $count=5 ?>
</tr>
</table><? } }?>
<br />
<p>&nbsp;</p>
<p><br />
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</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
Feb 29 '08
22 2050
nathj
938 Recognized Expert Contributor
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
Mar 3 '08 #21
hsriat
1,654 Recognized Expert Top Contributor
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_th e_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"><im g src="get_image. php?id=<? echo $rows['unique_id_of_t he_table']; ?>"></img></th>[/html]

* unique_id_of_th e_table : whatever unique id you are using.
Mar 3 '08 #22
nathj
938 Recognized Expert Contributor
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
Mar 3 '08 #23

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2451
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 http://www.macromedia.com/devnet/mx/dreamweaver/articles/php_cart.html. When I try to start a session or create a cookie, I get the following errors. Warning: Cannot send session cache limiter - headers already sent (output started at /wrapper_head2.php:27) in /cart.php on line 13 Warning: Cannot...
3
3321
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 (after I set the appropriate $_SESSION value) but I get the following error: Warning: Cannot modify header information - headers already sent by (...)
19
7928
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 limiter - headers already sent in /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php on line 14
4
2066
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 sun\css.php:1) in C:\Program Files\Apache Group\Apache2\htdocs\Rising sun\loginmeth.php on line 24 This is the login script stored in loginmeth.php ; <?php require_once 'config.php';?> <?php include 'opendb.php';?> <?php $errorMessage = ''; if...
5
2001
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 header information - headers already sent by (output started at C:\Inetpub ........login\include\header.php:9) in C:\Inetpub\vhosts\.....\httpdocs\login\login.php on line 23 And here is the content of the header.php page which is included in all my...
8
2399
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 page where is is to be validated then read into a MySQL table. Once that is done, the form is to send the user either back to the originating page, or to a logout page. I have several versions of this setup on my site that work well, so
2
2332
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
3
2849
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 /home/notasluz/public_html/administrador/Administrador.php:1) in /home/notasluz/public_html/administrador/verificaEntrada.php on line 2  Warning: Cannot modify header information - headers already sent by (output started at...
3
1427
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 User_Info_Other where user_id = '1'"); header("Content-type: image/gif"); while ($row = mysql_fetch_array($gotten)) {
10
2383
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 'connectdb.php'; $id = $_GET;
0
9700
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10310
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10068
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9121
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6841
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.