/    Sign up×
Community /Pin to ProfileBookmark

header("Location: ") Issues

Probably extremely simple, I just can’t see it. My PHP file starts off with this:

[code=php]<?php
$id = $_GET[‘id’];

if($id==””){
header(“Location: restaurants.php”);
}
[/code]

But then when I attempt to load the page I get this:

Warning: Cannot modify header information – headers already sent by (output started at /homepages/23/d108630418/htdocs/bellevue/restaurant.php:1) in /homepages/23/d108630418/htdocs/bellevue/restaurant.php on line 5

Warning: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 1 in /homepages/23/d108630418/htdocs/bellevue/includes/ezsql/ez_sql_mysql.php on line 204

You can see it here: [url]http://bellevue.com/restaurant.php[/url].

Now, what the heck is causing it? Nothing has be printed, there should be nothing before the header is sent, so why does it think the headers have already been sent?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@SyCoOct 27.2008 — Something else is being output to the screen before the header. It could be a space, even a invisible newline char or tab char.
Copy linkTweet thisAlerts:
@bejitto101authorOct 27.2008 — There is not a single thing there. Line 1 starts off with <?php and nothing else. There is nothing before the <?php either.

Is there any way to attach a file to a post? I could upload the file so people could take a gander at it.

I'll include all the code here just for kicks.

[code=php]<?php
$id = $_GET['id'];

if($id==""){
header("Location: restaurants.php");
}

include 'includes/prep2.php';
/* $query = "SELECT * FROM restaurants WHERE id=$id";
$result = mysql_query($query) or die("Query failed: ". mysql_error());
$row = mysql_fetch_array($result);*/

$rest = $db->get_row("SELECT * FROM locations WHERE id=$id");

//Some header fun, sets header tags
require_once 'includes/header.php';
$header = new HeaderClass();
$header->title = htmlspecialchars($rest->name). ' - Bellevue WA & Eastside | Bellevue.com';
$header->js = 'js/restaurant.js';
$header->js ='http://maps.google.com/maps?file=api&amp;v=2&amp;key=AB' .
'QIAAAABght1uh-cQUlt5pnst77MBS7UGDWNgMAJP-kKfwPBoJeb7xx4_3RBR' .
'HD9572v3xWlbakvdkhPmIqSKVVokOA';

$header->css = 'css/restaurant.css';
//$header->meta = Array('http-equiv'=>'Content-Type', 'content'=>'text/html; charset=utf-8');
$header->meta = Array('name'=>'description', 'content'=>'some text here for search engines');
unset($header);
?>


<div id="leftCol">
<div id="rest-info">
<div id="rest-img">
<img src="images/bellevue300x250.gif" alt="Restaurant"/>
</div>
<div id="rest-text">
<h1><?=$rest->name?></h1>
<p><?=$rest->cuisines?></p>
<?
$rating = round($rest->rating);
$stars="";
for($i=0; $i<$rating; $i++){
$stars .= "<img src="images/star.gif" alt="full star" />";
}
for($i=0; $i<(5-$rating); $i++){
$stars .= "<img src="images/star_empty.gif" alt="empty star" />";
}
?>
<p><?=$stars?> (<?=(int)$row['votes']?>) Votes | <a href="#">rate &amp; share your review</a></p>
<p><?=$rest->phone?></p>
<p><a href="<?=$rest->website?>"><?=$rest->website?></a></p>
<br />
<p>Nightlife: <?=$rest->tags?></p>
</div>
<br class="clear" />
</div>

<div id="map-wrapper">
<p><?=$rest->address?>, <?=$rest->city?> <?=$rest->zip?> | <a href="#">Directions</a></p>
<div id="map" style="height:370px; width:460px;"></div>
<div id="whats-nearby">
<p><strong>What's Nearby</strong></p>
<p class="smaller">Click to view on the map:</p>
<div id="whats-nearby-item">
<p><img src="images/mapicons/Restaurants_nav.gif" alt="map icon" /> Restaurants</p>
<p><img src="images/mapicons/Hotels_nav.gif" alt="map icon" /> Hotels</p>
<p><img src="images/mapicons/Bars_nav.gif" alt="map icon" /> Bars &amp; Clubs</p>
<p><img src="images/mapicons/Shopping_nav.gif" alt="map icon" /> Shopping</p>
</div>
</div>
<br class="clear" />
</div>
<div id="rest-descrip">
<div class="menu-items"> <a id="profile" class="restcontrols selected">Profile</a><a class="restcontrols" id="reviews">Reviews</a><a class="restcontrols" id="happenings">Happenings</a><br class="clear" /></div>

<div class="forms">
<div id="profile_control" class="x">
<div class="col-wrapper">
<div class="left-col">
<p><strong>Hours:</strong></p>
<p><strong>Happy Hour:</strong></p>
<p><strong>Late Night Happy Hour:</strong></p>
</div>
<div class="right-col">
<h3>Happenings at <?=$rest->name?></h3>
<p>Got an event or happening? <a href="#">Post your event here!</a></p>
</div>
<br class="clear" />
</div>
<div id="rest-reviews">
<h2>User reviews for <?=$rest->name?></h2>
<p><a href="#">Log in and share your review</a></p>
</div>
</div>
<div id="reviews_control"></div>
<div id="happenings_control">
<h2>Happenings at <?=$rest->name?></h2>
<p>Got an event or happening? <a href="#">Post your event here!</a></p>
</div>
</div>
</div>

</div>

<div id="rightCol">
<?php
include("modules/search.php");
include("modules/rest_featured.php");
include("modules/happenings.php");
?>
</div>

<?php
include("includes/footer.php");
?>[/code]
Copy linkTweet thisAlerts:
@SyCoOct 27.2008 — I remember years ago something like this and the details are fuzzy but it was something the file encoding being sent first. Try opening and resaving it in Textpad (free download from textpad.com) and making sure the file format matches your platform.
Copy linkTweet thisAlerts:
@SyCoOct 27.2008 — Yea, it's mentioned in the manual

http://us3.php.net/manual/en/function.header.php#82414 and the following comment

Most likely byte order markers being sent first. Check out your editor settings.
Copy linkTweet thisAlerts:
@bejitto101authorOct 27.2008 — Well I did what you said in Textpad and that fixed the errors. However in Dreamweaver, the editor I normally use, on all files the BOM are left out by default. My client uses Frontpage I believe, and sometimes, goes and modifies little snippets of code. Is Frontpage known to do this?
Copy linkTweet thisAlerts:
@SyCoOct 27.2008 — Yea it is. I have a copy of frontpage on my work PC. I searched the help and found this
Encode a text file


Warning Depending on the content type, if you reload or save the text file as a different encoding, you can lose the contents of the file.

On the File menu, click Open.

Locate and click the text file that you want, and then click Open.

Before you encode a text file, it is recommended that you save a backup copy.

Right-click the document window, and then click Encoding on the shortcut menu.

Do one of the following:

To reload the file, in the Reload the current file as box, click a different encoding, and then click Reload.

To save the file, in the Save current file as list, click the encoding you want , and then click Save As.

[/QUOTE]

Which opens a window including this option
Include a byte-order mark (BOM) when saving as Unicode [/QUOTE]
Checked by default.

Looks like you can select Unicode UTF-8 and uncheck the box. Then go kick your client in the nuts.

When I freelanced I included a clause in my contract that basically said 'you break it you bought it'. Why do people hire professionals and then think they can screw with the code you produce. Then expect you to fix their screwups for free shouting and screaming at you all the time. Wow sometime I miss being a freelancer, and sometimes I don't ?
Copy linkTweet thisAlerts:
@ayveghOct 28.2008 — AFAIK Dreamweaver throws in two characters in the beginning of every file it saves, for some odd reason. ?
×

Success!

Help @bejitto101 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.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...