473,626 Members | 3,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

header("Locatio n: ..."); Problem

I get the following message when trying to run my script:

"Warning: Cannot modify header information - headers already sent by (output
started at /var/www/html/newcustomer.php :23) in
/var/www/html/newcustomer.php on line 332"

....newcustomer .php:23 is where my script begins, at line 23.

before that line, only comments.

The script recives data from a form, checks if the customer exists, if so,
it updates the data otherwise inserts a new customer into the db. Also some
validation is done before writing to the db.

In advance, thanks for your time and advice.

FM>

And here's the flow of my script:

<?php
include 'db.inc'
include 'error.inc.

//init error string
$errorString = "";

//clean & trim POSTed values

... ... ...

//validate data
if (empty($formvar s["source"]))
$errorString .=
"\n<br>You must suply the name of the source.";

//validate other data

... ... ...

//end of validation

//check if errors exist
if (!empty($errorS tring))
{
//errors do exist, show them & exit
?>
<html>
<body>
<br>Errors were found.
<br>
<?=$errorString ?>
</body>
</html>

<?php
exit;
}

//if all data valid, open connection and load into the db
if (!(connection = @ .....))
die( ... );
if (!mysql_select_ db( ... , ... ))
showerror();

//Are the data being updated? Then update the database
if (!empty($cust_i d))
{
$query = "UPDATE customer SET " .
"source = \"" . $formvars["source"] . "\", " .
... ... ...
... ... ...
WHERE cust_id =$cust_id";
}
else
//Create query to insert the data

$query = INSERT INTO customer
... ... ...";

//Run the query on the customer table

... ... ...

//Is this an insert?
if (empty($cust_id ))
//find the cust_id of the new customer
$cust_id = mysql_insert_id ();

//Now redirect the customer to the receipt page
header ("Location: cust_receipt.ph p?cust_id=$cust _id");
?>
Jul 17 '05 #1
11 6064
In article <2p************ @uni-berlin.de>, Francisco Mendez wrote:
I get the following message when trying to run my script:

"Warning: Cannot modify header information - headers already sent by (output
started at /var/www/html/newcustomer.php :23) in
/var/www/html/newcustomer.php on line 332"
//check if errors exist
if (!empty($errorS tring))
{
//errors do exist, show them & exit
?>
<html>
<body>
<br>Errors were found.
<br>
<?=$errorString ?>
</body>
</html>

}

header ("Location: cust_receipt.ph p?cust_id=$cust _id");

http://be2.php.net/manual/en/function.header.php

Parts that may interest you:

Remember that header() must be called before any actual output is sent,
either by normal HTML tags, blank lines in a file, or from PHP. It is a
very common error to read code with include(), or require(), functions,
or another file access function, and have spaces or empty lines that
are output before header() is called. The same problem exists when
using a single PHP/HTML file.
Note: HTTP/1.1 requires an absolute URI as argument to Location:
including the scheme, hostname and absolute path, but some clients
accept relative URIs. You can usually use $_SERVER['HTTP_HOST'],
$_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a
relative one yourself:

--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
Jul 17 '05 #2
Tim Van Wassenhove wrote:
In article <2p************ @uni-berlin.de>, Francisco Mendez wrote: http://be2.php.net/manual/en/function.header.php


Hi Tim: Before I posted to the NG, I have RTFM, but i'm still not able to
solve my problem. I have sent a sample of code expecting someone were able
to help me to find a solution.

Anyway thx for your time.

FM>
Jul 17 '05 #3
Nel
"Francisco Mendez" <if****@prodigy .net.mx> wrote in message
news:2p******** ****@uni-berlin.de...
Tim Van Wassenhove wrote:
In article <2p************ @uni-berlin.de>, Francisco Mendez wrote:

http://be2.php.net/manual/en/function.header.php


Hi Tim: Before I posted to the NG, I have RTFM, but i'm still not able to
solve my problem. I have sent a sample of code expecting someone were able
to help me to find a solution.

Anyway thx for your time.

FM>

FM, you may wish to read Tim's message again. He has indeed re-listed the
errant code above his reply and then explained why it's a problem.

Apologies for repeating Tim's message, but in clear terms - you cannot
output anything before a header command.

not a single space, not an echo, not "<HTML> blah blah </HTML>".

It's that simple. If you must display some html (briefly!) before
redirecting then you should use the refresh meta tag.
http://webdesign.about.com/cs/metatags/a/aa080300a.htm

Nel.
Jul 17 '05 #4
I noticed that Message-ID: <2p************ @uni-berlin.de> from Francisco
Mendez contained the following:
Hi Tim: Before I posted to the NG, I have RTFM, but i'm still not able to
solve my problem. I have sent a sample of code expecting someone were able
to help me to find a solution.


You can't have ANY HTML output before the header call. It could be as
simple as a blank line at the top. Or HTML comments.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #5
"Francisco Mendez" <if****@prodigy .net.mx> wrote in message
news:2p******** ****@uni-berlin.de...
Tim Van Wassenhove wrote:
In article <2p************ @uni-berlin.de>, Francisco Mendez wrote:

http://be2.php.net/manual/en/function.header.php


Hi Tim: Before I posted to the NG, I have RTFM, but i'm still not able to
solve my problem. I have sent a sample of code expecting someone were able
to help me to find a solution.

Anyway thx for your time.


You also stated that you had "comments" prior to line 23 but that your
script didn't start until line 23. What was above line 23?

- Virgil
Jul 17 '05 #6
Virgil Green wrote:


You also stated that you had "comments" prior to line 23 but that your
script didn't start until line 23. What was above line 23?

- Virgil


/* begin comments line #1
.....
....
*/ line #22
<?php
....

Just that only comments from line to line 22, script begins in line 23 with
the usual <?php
FM>
Jul 17 '05 #7
Geoff Berrow wrote:
I noticed that Message-ID: <2p************ @uni-berlin.de> from Francisco
Mendez contained the following:
Hi Tim: Before I posted to the NG, I have RTFM, but i'm still not able to
solve my problem. I have sent a sample of code expecting someone were able
to help me to find a solution.


You can't have ANY HTML output before the header call. It could be as
simple as a blank line at the top. Or HTML comments.


Geoff:

I have from line 1 to line 22 only cpmments eclosed within php markers, i.e.

<?php line #1
/*
....
....
*/
?> line 22
<?php
//Script begins here

Jul 17 '05 #8
I noticed that Message-ID: <2p************ @uni-berlin.de> from Francisco
Mendez contained the following:
?> line 22
<?php


And what do you think is between line 22 and line 23? :-)

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #9
"Francisco Mendez" <if****@prodigy .net.mx> wrote in message
news:2p******** ****@uni-berlin.de...
Geoff Berrow wrote:
I noticed that Message-ID: <2p************ @uni-berlin.de> from Francisco
Mendez contained the following:
Hi Tim: Before I posted to the NG, I have RTFM, but i'm still not able tosolve my problem. I have sent a sample of code expecting someone were ableto help me to find a solution.
You can't have ANY HTML output before the header call. It could be as
simple as a blank line at the top. Or HTML comments.


Geoff:

I have from line 1 to line 22 only cpmments eclosed within php markers,

i.e.
<?php line #1
/*
...
...
*/
?> line 22
<?php
file://Script begins here


Remove the end and beginning tags on 22 and 23. You have a carriage return
and/or line feed between them and that counts as output, I believe.

- Virgil

Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4432
by: Stijn Goris | last post by:
Hi all, I have a question regarding the header function. I send a browser to a certain page (eg first.php ) wich sends no output to the browser. This page sends the browser to another page (eg second.php) with the header("Location:") function. second.php doesn't either send any output to the browser. The browser is then send to another page also with the header() function. Now my problem: I have to send user and password data...
13
11792
by: Dave Smithz | last post by:
Hi there, I have a php script that does some form input validation. As it verifies each field if the field has incorrect data, it appends an error message to an $error array. E.g. if (an_error = true) { $errors.="<tr><td>You have note entered a surname. This is mandatory date of birth incorrectly.</td></tr>"; }
5
3209
by: Duderino82 | last post by:
I'm working on a very simple peace of php where basically there is a form and 3 buttoms. One refreshed the page, one posts the form, and another one (since this form contains values of a record) deletes the record. The sintax is this one: if ($delete) { header ("Location: $redirect?del=$code&table=$tab"); exit; }
2
4122
by: hagenaer | last post by:
Hello, I'm building a simple shopping cart to work with PayPal. I'd like to have the user post his basket to my page, validate the input, then redirect him _with his validated form data_ to PayPal using header("Location:"). I could just have the user submit his form to PayPal, but then I don't have any control over what he submits (tweaking the form is easy). I can include the form data as a search string in the redirect URL but that creates...
4
9160
by: andre rodier | last post by:
Hello, I need to display or propose a jpeg image on a web page. When I need to display the image, I use this code : header("Content-Length: $fileSize") ; header("Content-Type: $type") ; header("Content-disposition: inline") ; header("Location: $imageURL"); And when I need to propose the image to save, I use this one :
0
8268
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
8202
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
8641
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...
1
8366
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7199
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
4093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2628
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
1
1812
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.