Hello, I'm fairly new to php. I have a two page's, one where user creates account. The other one is for the user to insert other information. If user completes both pages I want to direct them to their personal page, else, direct them to the second page to insert the other data if they did not do it during the first session.

Basically, If user completed registration on 2nd page go to XXX.php
Else go to yyy.php. (to complete registration)

By the way, I'm using a parent and child table with a foreign key.
Thanx!

Recommended Answers

All 13 Replies

evstevemd is absolutely correct,
here is the basic code for header:
if registration complete

header('Location:xxx.php');

else

header('Location:yyy.php');

Yes, thank you. But how can my site know if the user submitted the second form or not.

i recommend you use javascript redirect

echo "<script>window.location='form2.php'</script>";

to avoid annoying error on php header() function, about already sent output.
regards on how you will know if the 2nd form is successfully and correctly filled up. you can add a field in your database table where you store your record. you can add a 'status' field, and set it to 1 or 0, let's say 1=complete, 0=incomplete.

Member Avatar for diafol

Personally, I'd stay clear of js if possible - header() if used correctly shouldn't cause an error ("headers already sent").

Am I correct in assuming your db:-

table1 (members - records created on registration):
id (PK)
username
pw
email
(etc)
table2 (profile - records created when profile form sent):
id (PK)
user_id* (FK)
avatar
hobbies
(etc)

Just check for the existence of a record in the profile table (matching user_id). If one exists - go to the personal page, else go to the profile page. However VD's status is a good solution.

Personally, I'd stay clear of js if possible - header() if used correctly shouldn't cause an error ("headers already sent").

haha... sorry about that master... i always get trouble with header(), and i dont know how to fix it. thats why i user javascript to avoid the hassle.

However VD's status is a good solution.

thanks dude... but your approach is a lot better.. hehe

Can you please explain your request more clearly.

Thnx for all answers. To explain question better:
The answers I got seem correct. My table is set just like ardav said.
Anyway, I having trouble trying to figure how to write the code to verify if form 2 was complete, if yes direct them to personal page after logging in, if no, direct them to page 2 so they can complete form 2. ardav answers sounds right, so do others but it just about going about writing the code and where. Stuck for a while.
Thax again for answers!

Assuming you have a column in your database entitled "register_status" or something like that, and that user has logged in:

1- Query database for user info.

$query = "SELECT * FROM Users WHERE id='$userid' ";
$result = mysql_query($query) or die(mysql_error() );
$user_data = mysql_fetch_array($result);

2- Test register status.

if($user_data['register_status'] == 2) {    // Form 2 complete
  header("Location: profile.url");
}
else {
 header("Location: form2.url");
}

Thank you! I'm just a little confused on the status column. I created one but I really not sure how to use it. Please explain how to use a status column. Nevertheless, much progress!

Personally, I'd stay clear of js if possible - header() if used correctly shouldn't cause an error ("headers already sent")..

JS is the best way to go but only if you are sure your users will not turn off JS in their browsers. No one in the world can guarantee that so here is what I do:
1. Create Pure XHTM/PHP site
2. Add JS to do PHP stuffs at Client.
If user's JS is on some basic things like empty field will be dealt at user level and relieve server of unnecessary queries

Cheers ;)

When you insert the contents of the second form to the database, insert the number "2" into the "status" column to indicate that the user has submitted the information.

Yes, thank you. But how can my site know if the user submitted the second form or not.

ANS: You could always check all the variables while your still on that same web page. All you need to do is this...

i.e.

if($_POST['data1'] == "" || $_POST['data2'] == "")
{
      echo "You can not leave this page."
}
else
{
 //You will be redirected
      echo "<script>window.location = 'http://yoursite.com/user_profile.php'</script>";	
}

I hope this would help!! :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.