Form redirection with multiple variables
<p>I found a <a href="http://phptutorial.codepoint.net/php_redirection" rel="nofollow">wonderful example</a> on form redirection when there is an error with the form elements. In validation.php the system checks if there is an error and if it's true it redirects the user to the form page.
My question is what if I have more than one form element?</p>

<p>As you see I renamed user_name to app_name and I added a new variable (adtext) so now I get two error messages when both form elements have some error (right now they not equal to a certain word), but I don't know what to do with the $query_string variable so the url would contain the second variable and its value as well. </p>

<p>This is how the url of the form page (adparameters.php) looks like when I click the submit button and there is an error with $appname:</p>

<p>/adparameters.php?appname=aa&amp;error=App%20name%20is%20requiredAd%20text%20is%20required</p>

<pre><code>&lt;?php
# validate.php

$appname = trim($_POST['appname']);
$adtext = trim($_POST['adtext']);
$error = '';

if ($appname != 'myapp') $error = 'App name is required&lt;br /&gt;';
if ($adtext != 'mytext') $error = $error . 'Ad text is required&lt;br /&gt;';


$query_string = '?appname=' . $appname;


$server_dir = $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . '/';

header('HTTP/1.1 303 See Other');

if ($error != '') {

   // Back to register page
   $next_page = 'adparameters.php';

   // Add error message to the query string
   $query_string .= '&amp;error=' . $error;

   // This message asks the server to redirect to another page
   header('Location: http://' . $server_dir . $next_page . $query_string);
}
// If Ok then go to confirmation
else $next_page = 'confirmation.php';

/*
Here is where the PHP sql data insertion code will be
*/
// Redirect to confirmation page
header('Location: http://' . $server_dir . $next_page . $query_string);
?&gt;
</code></pre>

<p>The greatness of this code is that if I type something in the first input type object and it doesn't equal 'myapp' it is still filled with the text after redirection. That's what I want with the second object as well.</p>
