tags:

views:

92

answers:

2

I'm fairly new with PHP and I am messing around with a login/registration system. I setup my sample website using a PHP-SWITCH script I found a while back:

    <?php
  switch($_GET['id']) {
  default: include('home.php');
  /* LOGIN PAGES  */
  break; case "register_form":
   include ('includes/user_system/register_form.php');
  }
 ?>

On the registration page the form links to my "register.php" which checks the validity of the form and to check for any blank fields and so on. "register.php" is supposed to refresh the page and add a reason to what the user did wrong when submitting the form.

On my "register_form.php" page, which holds the actual form. This field is hidden until the user makes a mistake.

    <?php if (isset($reg_error)) { ?>
  <span class="red"><?php echo $reg_error; ?></span>, please try again.
 <?php } ?>

My "register.php" checks the form for all the errors. Here's the bit of code that will refresh the page with the reason for the error:

    // Check if any of the fields are missing
 if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['confirmpass'])) {
 // Reshow the form with an error
 $reg_error = 'One or more fields missing';
 include 'register_form.php';

Now after I submit the form without any fields filled out I get the error code, but it refreshes to the actual "register_form.php". The problem with this is that because of my PHP-SWITCH script (helps me manage the site a lot easier) I don't have any formatting on that page. The actual URL to my "register_form.php" would be: "index.php?id=register_form". Now I have tried several different things such as changing it to:

include 'index.php?id=register_form'

And also changing it to:

header(location:index.php?id=register_form')

Unfortunately all this does is refresh the page without the reason for the error. I know this can be easily solved by just adding a Javascript Validator but I'd like to know if it is possible to refresh the page with the error using either "include" or "header()" while having a PHP-SWITCH script on the website.

A: 

Sorry for the vaugness of my answer:

  • The switch default should be at the very end of your switch statement
  • You shouldn't use a switch statement as gate.
  • You must break; after the first case:.
  • Dont use eviroment vars 'GET' in you includes, because your includes arent supposted to be requested via the server.
  • You header function param is syntactically wrong.
  • And to answer your last question, No, because you're always assigning register_form to $_GET['id'].
Babiker
you mean `break;` not `brake;'
Serge
A: 

What are some good ways to layout my website? I've used include('file.php') to layout my website easier but I've always used switch to have the dynamic content section. What are some ways to still have the dynamic content section and have it function properly with that login script

Steve Rivera