/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Help with header(‘Content type:’)

Hello to all,

I am trying to retrieve data generated in a php script to put into my html page. The problem I am having is that the data is not being returned. It is not a problem of connection: I have tested them and they work. I think my problem may lie in the use of the function “header()” in my php script. I am not sure how to return the text generated from my php script. Here is the php code I am using:

[code=php] header( ‘Content type:text/plain’) ;

while( $row = mysql_fetch_assoc($result) )
{
foreach ($row as $col)
{
echo “<option>$col</option&gt”;
}
}
[/code]

I am trying to link this back up with my html page with the following code

[code=html] // select tag
var selectTag = document.getElementById(“locusSelect”) ;

if( xmlRequest.status == 200 )
{
// put info into select tag
selectTag.innerHTML = xmlRequest.responseText ;
//alert(“Page Found”) ;

}
[/code]

The output of my php script looks like this:

[CODE]Warning: Cannot modify header information – headers already sent by (output started at /Users/Greg/Sites/homework7-8/getLoci.php:10) in /Users/Greg/Sites/homework7-8/getLoci.php on line 12
<option>A12345</option><option>B23456</option><option>C34567</option> [/CODE]

Note: line 12 is the header() function

I am not sure what I am doing wrong. I am trying to return a list of names from a database to input as options in a select tag upon loading of page.

Any help would be great

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@felgallNov 16.2008 — The problem is in your PHP file where you have something outside of the <?php ?> tags above the header() statement. Check that you don't have any space at all in the file above the <?
Copy linkTweet thisAlerts:
@TheDragonRebornauthorNov 16.2008 — Still receiving error when I took out all non-php code. Also, what argument do I use for the header function to return the output of the script:

[CODE]<option>A12345</option><option>B23456</option><option>C34567</option>[/CODE]

Or is there another way for me to pass this data back to my html script?
Copy linkTweet thisAlerts:
@TheDragonRebornauthorNov 16.2008 — Solved my problem. here is what i changed in php if anyone else has similar problems

[code=php]while( $row = mysql_fetch_array($result) )
{

$display_string .= "<option>" ;
$display_string .= $row[0] ;
$display_string .= "</option>" ;
}

// Loci list
echo $display_string ;[/code]
×

Success!

Help @TheDragonReborn spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...