PHP Classes

Redirect to another page...

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  How to Show Google Ma...  >  All threads  >  Redirect to another page...  >  (Un) Subscribe thread alerts  
Subject:Redirect to another page...
Summary:need to go to another page after form Submit if clicked...
Messages:3
Author:Charles deRees
Date:2010-06-06 07:50:25
Update:2010-06-11 23:49:19
 

  1. Redirect to another page...   Reply   Report abuse  
Picture of Charles deRees Charles deRees - 2010-06-06 07:50:25
I have worked out pretty much all things I would like to do with form class although I am struggling trying to redirect to another page after the form is submitted. Ideally I want to pass 3 parameters through a URL to script to update a MySQL table. Something I can in PHP without the class fairly easily as per code below....

header("Location:PeopleUpdate.php?pageNum_People=$_GET['pageNum_People']&totalRows_People=$_GET['totalRows_Customers']&Lat=$latitude&Long=$longitude&PID=$PID");

all I know is that I should place the redirect into the if($doit) section but I would really be grateful if someone can help me workout how to do the same using this form.php class.

Many thanks in advance.

Charlie

  2. Re: Redirect to another page...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-06-06 08:23:29 - In reply to message 1 from Charles deRees
If you know what you want update a database table when the form is submitted, why don't you update the table right in the same script that processes the form?

You can redirect using the Header Location statement as you shown, but if you do it your application may be prone to security issues as somebody may realize that you are updating the database in another page and go directly to it and pass some invalid values that would not pass the form validation you already implemented in the form page.

  3. Re: Redirect to another page...   Reply   Report abuse  
Picture of ZZorro ZZorro - 2010-06-11 23:49:19 - In reply to message 1 from Charles deRees
Do not pass information via the http headers. Use the built-in variable handling in PHP.

Here is a snippet of get the value from a form and saving them to a database:

*** this code is part of an html input form
<form id="registerForm" method="post" action="/register/save_new.php">

<label for="FName">First Name:<span class="red">*</span></label>
<input type="text" id="FName" class="required" name="FName" size="30" maxlength="30" tabindex="2" />
<br>

<label for="LName">Last Name:<span class="red">*</span></label>
<input type="text" id="LName" class="required" name="LName" size="30" maxlength="30" tabindex="3" />

<div id="submit">
<input class="submit" type="submit" value="Submit"/>
</div>
<br />

</form>
*** end of input form ****

save_new.php sample code

<?php>

$link = mysql_connect('mydb.myhostingprovider.com', 'login name', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Connected successfully';
mysql_select_db(registrations);

$Salutation = Trim(stripslashes($_POST['Salutation']));
$FName = TitleCase(mysql_real_escape_string(Trim(stripslashes($_POST['FName']))));
$LName = TitleCase(mysql_real_escape_string(Trim(stripslashes($_POST['LName']))));

// save the information to the database

$query="INSERT INTO registration (Salutation, First_Name, Last_Name)
VALUES('$Salutation', '$FName', '$LName')";

mysql_query($query) or die ("Error in query: $query");
mysql_close();

// Send confirming e-mail
include ("send_email.php");

// or use the following
// print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";

?>