loading pages using php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shadow_blade47
Forum Newbie
Posts: 12
Joined: Fri Nov 07, 2003 3:41 am

loading pages using php?

Post by shadow_blade47 »

Hi there,
I'm quite new to php, but i'm working on a quite complex registration script. It works fine, and will add users/encrypted passwords/e-mail addresses to a database etc. But after it has done that i want it to load a different page that says successfull registration. The form is on the same page as the validation script, and works using:
$_SERVER['PHP_SELF]
The idea is that when the form is submitted it then reloads the page, validates the values of each field and does one of two things - displays an error message if the fields have bad values, or submits the data to the databse if the values are correct. Here is a the last bit of the validation/data submital script:

//if all the values are correct with no errors the following script is run:

$query = "INSERT INTO user (user_id, user_name, first_name, last_name, password, email, remote_addr, date_created)
VALUES (NULL, '$User_name', '$First_name', '$Last_name', '$password', '$Email1', '$user_ip', NOW())";
$result = mysql_query($query);
if (!$result) {
$feedback = 'ERROR - MySQL has encountered a technical failure - contact the administrator,';
return $feedback;
} else {

After else I'm looking for a line to put that will load up a page called success.php. Does anybody know how to do this without using headers? Thanks a lot in advance...

james moore
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

What about this, uses JavaScript

Code: Select all

$query = "INSERT INTO user (user_id, user_name, first_name, last_name, password, email, remote_addr, date_created) 
VALUES (NULL, '$User_name', '$First_name', '$Last_name', '$password', '$Email1', '$user_ip', NOW())"; 
$result = mysql_query($query); 
if (!$result) { 
   $feedback = 'ERROR - MySQL has encountered a technical failure - contact the administrator,'; 
   return $feedback; 
} else { 
   echo "<script language="javascript">";
   echo "document.location='success.php'";
   echo "</script>";
}
Mark
shadow_blade47
Forum Newbie
Posts: 12
Joined: Fri Nov 07, 2003 3:41 am

thanks

Post by shadow_blade47 »

cheers m8, i cant beleive i overlooked using javascript lol. Having said that i did try it once before and it never worked so i decided that i couldnt use it, obviously i was very wrong. I owe ya big time

thank you
-james
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

I'm working on basically the same thing right now. Here's my solution.

if($err == true) {
echo 'ERROR MESSAGE HERE';
} else {
header("Location: successful.php");
}

The else statement will redirect the browser to successful.php IF there is no error. Now, your script is a lot more complicated than this, but this is just a raw example. No need for Javascript even though it would work. This is just much more simple. Also, don't validate a form on the same page as the form. So send the data from form.php to validate.php, validate the data, and then redirect to the appropriate page using the header("Location: page.php"); function. I hope this helps out.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

you could always say add the success message in the same if statement as the INSERT thing..
Post Reply