Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6932461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:42:32+00:00 2026-05-27T11:42:32+00:00

Ive got this register script that puts the information into a mysql database. now

  • 0

Ive got this register script that puts the information into a mysql database. now it all works fine and when someone does something wrong its says the error (e.g. “Username not defined”)

but when it goes wrong it does not look very good because it just displays the message on an empty page, so i thought i would make it redirect to the form page and display the message there.

here is the working script

$forename = $_POST['forename'];      
$surname = $_POST['surname'];       
$email = $_POST['email'];    
$password = $_POST['password'];    
$username = $_POST['username'];

$errors = array();

 if(!$username) {

    $errors[] = "Username is not defined";

 }

 if(!$password) {

    $errors[] = "Password is not defined";

 }

and it continues.

now i just thought i could do this

 $errors = array();

 if(!$username) {

    $errors[] = header( 'Location: http://localhost/muiltabledistractions/#!/page_register_error-Username-is-not-defined' ) ;

 }

 if(!$password) {

    $errors[] = "Password is not defined";

 }

but no, all it does is ignore it.

could someone please help me

please feel free to ask for more of the script if you need it

many thanks connor

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:42:33+00:00Added an answer on May 27, 2026 at 11:42 am

    it does not look very good because it just displays the message on an empty page,

    What’s the problem?
    Why not to show the form again? with fields already filled.
    This is going to be a user-friendly interface.

    Just include your form in the same page with fields populated.
    That’s more common way than your redirects to blank form.

    This is called POST/Redirect/GET pattern and here goes a short example of it:

    the code

    <?  
    if ($_SERVER['REQUEST_METHOD']=='POST') {  
    
      $err = array();
      //performing all validations and raising corresponding errors
      if (empty($_POST['name']) $err[] = "Username field is required";  
      if (empty($_POST['text']) $err[] = "Comments field is required";  
    
      if (!$err) {  
        // if no errors - saving data 
        // and then redirect:
        header("Location: ".$_SERVER['PHP_SELF']);
        exit;
      }  else {
        // all field values should be escaped according to HTML standard
        foreach ($_POST as $key => $val) {
          $form[$key] = htmlspecialchars($val);
        }
    } else {
      $form['name'] = $form['comments'] = '';  
    }
    include 'form.tpl.php';
    ?>  
    

    the template

    <? if ($err): ?>
      <? foreach($err as $e): ?>
    <div class="err"><?=$e?></div>
      <? endforeach ?>
    <? endif ?>
    <form>
      <input type="text" name="name" value="<?=$form['name']?>">
      <textarea name="comments"><?=$form['comments']?></textarea>
      <input type="submit">
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ive got an object that looks like this with print_r(): SimpleDOM Object ( [0]
I've got an app that register a database for the user if he/she signs
i've got this tables in my database. alt text http://img166.imageshack.us/img166/3133/testdbschemafy5.png With Entity Framework i
I've got a custom control ive created that is instanced in my view, in
I've got a Django-based site that allows users to register (but requires an admin
I've got this script and it produces the following error: 001 Checksum failure This
I wanted to pick your minds... So I've got this View that allows for
I've got an ASP.NET application that uses the CreateUserWizard to register new users. Part
Is there an event that I can register that will be executed after all
I've got a class which is generating an event. Normally I register with this.obj.testEvent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.