473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Page redirection doesn't work using header function

Hi

I'd like to forward users to a 'thank-you' page after they've submitted a form.

I used this code and it worked perfectly till yesterday;

header("Location: http://www.ernestoow.com/mudlands/bedankt.html");

Right now..after submitting the data, the form refreshes and is empty again..although the submitted data is inserted into the database and a confirmation email is sent to the submitter.

What can be the problem?


full code;

[php]

<?



if (isset($_POST['Submit']))
{
$voornaam = $_POST['voornaam'];
$achternaam = $_POST['achternaam'];
$adres = $_POST['adres'];
$postcode = $_POST['postcode'];
$plaats = $_POST['plaats'];
$telnummer = $_POST['telnummer'];
$dagen = $_POST['dagen'];
$email = $_POST['email'];

if(!$_POST['voornaam'] || !$_POST['achternaam'] || !$_POST['adres'] || !$_POST['postcode'] || !$_POST['plaats'] || !$_POST['telnummer'] || !$_POST['dagen'] || !$_POST['email'])


{
die(

'<html>
<title>mudlands</title>
<link href="stylesheet.css" type="text/css" rel="stylesheet">
<body>

<div id="header">

<img src="mudlandsheader.jpg" border="0">

</div>

<div id="menu">

<b>Vrijwilliger</b>
<br>
&nbsp; &nbsp; <a href="inschrijven.php">Inschrijven</a>
<p>
<b>Coordinator</b>
<br>
&nbsp; &nbsp; <a href="vrijwilligers.php">Inschrijvingen</a>
<br>
&nbsp; &nbsp; <a href="search.php">Zoeken</a>

</div>

<div id="back">
</div>

<div id="main">
<p>
Je hebt niet alle velden ingevuld!
</div>

</body>
</html>'

);
}


$sql = "INSERT INTO VRIJWILLIGER(VOORNAAM, ACHTERNAAM, ADRES, POSTCODE, PLAATS, TELNUMMER, EMAIL) VALUES ('$voornaam', '$achternaam', '$adres', '$postcode', '$plaats', '$telnummer', '$email')";

mysql_query($sql) or die ("SQL1: ".mysql_error());

$query = "SELECT VRIJWILLIGER_ID, TELNUMMER FROM VRIJWILLIGER
where TELNUMMER = $telnummer";

$result = mysql_query($query)
or die("Er is een fout opgetreden");


$id=mysql_result($result,"VRIJWILLIGER_ID");


$datum_inschrijving = date("j F, Y, G:i");


$sql2 = "INSERT INTO INSCHRIJVING(VRIJWILLIGER_ID, DAGEN, DATUM_INSCHRIJVING) VALUES ('$id', '$dagen', '$datum_inschrijving')";

$result2 = mysql_query($sql2)
or die("Er is weer een fout opgetreden");


// Email versturen na aanmelding. $email is al bekend
// Subject
$subject = "Aanmelding Mudlands Festival";
// Bericht
$message = "blablabla";
mail($email, $subject, $message, "From: info@ernestoow.com");

header("Location: http://www.ernestoow.com/mudlands/bedankt.html");


}

?>

<html>
<title>mudlands</title>
<link href="stylesheet.css" type="text/css" rel="stylesheet">
<body>

<div id="header">

<img src="mudlandsheader.jpg" border="0">

</div>

<div id="menu">

<b>Vrijwilliger</b>
<br>
&nbsp; &nbsp; <a href="inschrijven.php">Inschrijven</a>
<p>
<b>Coordinator</b>
<br>
&nbsp; &nbsp; <a href="vrijwilligers.php">Inschrijvingen</a>
<br>
&nbsp; &nbsp; <a href="search.php">Zoeken</a>

</div>

<div id="back">
</div>

<div id="main">
Inschrijven


<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<p>

<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="120">
<font face="Arial, Helvetica, sans-serif" size="2">
Voornaam:
</font>
</td>
<td>
<input name="voornaam" type="text" id="voornaam" maxlength="30" />
</td>
</tr>
<tr>
<td width="120">
<font face="Arial, Helvetica, sans-serif" size="2">
Achternaam:
</font>
</td>
<td>
<input name="achternaam" type="text" id="achternaam" maxlength="30" />
</td>
</tr>
<td width="120">
<font face="Arial, Helvetica, sans-serif" size="2">
Adres:
</font>
</td>
<td>
<input name="adres" type="text" id="adres" size="40" maxlength="50" />
</td>
</tr>
<td width="120">
<font face="Arial, Helvetica, sans-serif" size="2">
Postcode:
</font>
</td>
<td>
<input name="postcode" type="text" size="9" maxlength="7" id="postcode" />
</td>
</tr>
<td width="120">
<font face="Arial, Helvetica, sans-serif" size="2">
Plaats:
</font>
</td>
<td>
<input name="plaats" type="text" id="plaats" maxlength="40" />
</td>
</tr>
<td width="120">
<font face="Arial, Helvetica, sans-serif" size="2">
Mobiel nummer:
</font>
</td>
<td>
<input name="telnummer" type="text" value="06" size="13" maxlength="10" id="telnummer" />
</td>
</tr>
<td width="120">
<font face="Arial, Helvetica, sans-serif" size="2">
E-mail:
</font>
</td>
<td>
<input name="email" type="text" size="35" maxlength="30" id="email" />
</td>
</tr>
<td width="120">
<font face="Arial, Helvetica, sans-serif" size="2">
Beschikbaarheid:
</font>
<br>
<font face="Arial, Helvetica, sans-serif" size="1">
(dagen)
</font>
</td>
<td>
<select name="dagen" id="dagen" size="2">
<option value="2">2</option>
<option value="5">5</option>
</td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Registreer" />
<input name="Clear" type="reset" id="Clear" value="Wissen" />
</p>

</form>
</div>

</body>
</html>
[/php]
Oct 25 '06 #1
8 4109
Hi

I'd like to forward users to a 'thank-you' page after they've submitted a form.

I used this code and it worked perfectly till yesterday;

header("Location: http://www.ernestoow.com/mudlands/bedankt.html");

Right now..after submitting the data, the form refreshes and is empty again..although the submitted data is inserted into the database and a confirmation email is sent to the submitter.

What can be the problem?
...
Warezguy,
I just tried your script live and it is reporting an SQL error which is most likely the problem, not your php header redirecting statement.

View the HTML source after submitting your form.

Also, I ran your script on my server and it redirected beautifully, but of course, since I didn't have your database I remarked the MySQL DB specific lines of code.

The HTML source contained:
'SQL1: Duplicate entry '06' for key 2'

Typically if you expect '06' to be entered more than once into your table, the field in your database needs to allow duplicates... this might be fixed by making it so the field holding the '06' value is not indexed and is allowed to have duplicate fields. I use MSSQL Server, so I don't have any advice on changing the properties of the field in question.

If you're convinced it's a header issue, obviously make sure the header location line if the first line of code to send data back to the client side. If you have any whitespace above your first <?php that can cause it to throw warnings (because the ouput is already started and headers need to come before normal HTTP output, otherwise you get one of these (which should be highly visible BTW):

'Warning: Cannot modify header information - headers already sent by (output started at ...'

but also check the source for this message too, as sometimes it's buried in a comment or a select HTML entity or other hiearchtically built HTML object that doesn't necessarily get drawn on the screen.
Oct 26 '06 #2
Warezguy,

The HTML source contained:
'SQL1: Duplicate entry '06' for key 2'

Typically if you expect '06' to be entered more than once into your table, the field in your database needs to allow duplicates... this might be fixed by making it so the field holding the '06' value is not indexed and is allowed to have duplicate fields. I use MSSQL Server, so I don't have any advice on changing the properties of the field in question.
Thanks for putting effort in this :)

The 06-thing is the place where people are able to enter their cellphone-number. Cellphonenumbers start with 06 in holland so thats why the 06 is already entered to make it more easy :) The cellphonenumber should be unique in the database by the way.

Anyway, i'll try your suggestions and let know if it worked out or not.
greets
Oct 27 '06 #3
ronverdonk
4,258 Expert 4TB
Very dangerous: inserting data in your database straight from the $_POST and selecting from the database without any sanitizing of the $_POST array variables. You are prone to hackers!

Ronald :cool:
Oct 27 '06 #4
Very dangerous: inserting data in your database straight from the $_POST and selecting from the database without any sanitizing of the $_POST array variables. You are prone to hackers!

Ronald :cool:
yes security is an important issue although the festival is fictional fortunately ;) is it useful to remove html/php tags by using the strip_tags function or aint that sufficient?



2 tomongous;
i removed some white spaces at the top of the page between 2 parts of php-code and it worked out. the redirection function is working again :)
Oct 30 '06 #5
vssp
268 100+
If you want to headder working

1. No html code berfore the header function
2. No eco stement enter berfor the header function

Thanks
vssp
Nov 2 '06 #6
exoskeleton
104 100+
Good day Sir Ronald,

i just read your reply...i would like to know how to secure the database as you said about sanitizing of the $_POST array variables...can you give me an idea how to do it? please..

thank yo sir ronald

Very dangerous: inserting data in your database straight from the $_POST and selecting from the database without any sanitizing of the $_POST array variables. You are prone to hackers!

Ronald :cool:
Nov 3 '06 #7
yeah im curious too :)
Nov 8 '06 #8
ronverdonk
4,258 Expert 4TB
Let me start with quoting an old web-developer's adagium about data coming in from an external source, either POST or GET: "NEVER TRUST ANYTHING THAT COMES FROM OUTSIDE".

It would go too far to describe to you, in extenso, the dangers of Cross Site Scripting, SQL injection or form spoofing, but maybe I may point you to one of the web security gurus, who knows a lot more about it then I do, Chris Shiflet.

Cross Site Request forgeries
Form spoofing
SQL Injection
Session hijacking

There are always hackers (destructive ones, in soccer they are called hooligans) looking for forms, sessions and url parameters that can be stolen, taken over and/or injected. That is why you must sanatise/cleanse any input coming from outside.

Ronald :cool:
Nov 9 '06 #9

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

Similar topics

2
by: Topspin | last post by:
I'm running PHP on Windows, but that's just the local test... in production it will be on Apache. I am not using PHP as a CGI. I want to perform redirection of the user's browser if the user...
5
by: Jerry | last post by:
Hi All I would very much appreciate your help: I have two scripts alternating in the background triggering themselves mutually. Here is how: 1.) Script A does something and then calls Script...
6
by: MooreSmnith | last post by:
When I navigate to the next page using Response.Rediect("MyNextPage.aspx") current page Page_Load event is called. What I may wrongly understood is that post back will happen whenever there is any...
10
by: Eric Lindsay | last post by:
This may be too far off topic, however I was looking at this page http://www.hixie.ch/advocacy/xhtml about XHTML problems by Ian Hickson. It is served as text/plain, according to Firefox...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
13
by: Stephen Kay | last post by:
Is there a way to redirect every single page on an existing web site through a php function? In other words, say I have a whole functional HTML web site, never written to use any php. Now I...
13
by: souissipro | last post by:
Hi, I have written a C program that does some of the functionalities mentionned in my previous topic posted some days ago. This shell should: 1- execute input commands from standard input,...
25
by: Marcel | last post by:
I have a person class adn i want to derive an object of that class on one page and pass that object to a next page but that does not work for me and i do not understand why. Here is de code: ...
3
by: Shawn Northrop | last post by:
Awhile ago i built a login script using php/mysql. At the end of the script i called a function header(location: (I don't remember exact sytax). This would redirect the page. Recently i have...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...

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.