Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2004
    Posts
    17

    Problems with registration form - I'm puzzled!

    Hi there,

    I'm using the code below as part of my registration script. I've only posted what was relevant. It consists of two pages, register.php and confirm.php. Register.php submits the data and confirm.php processes it. Below is the coding in confirm.php I'm having trouble with...

    PHP Code:
    if($name == "") {
    $nameerror "you didn't enter your name.";
    }

    if(
    $surname == "") {
    $surnameerror "you didn't enter your surname.";
    }

    if(
    $email == "") {
    $emailerror "you didn't enter an email address.";
    }

    if(
    $username == "") {
    $usernameerror "you didn't enter a username.";
    }

    if (
    $password == "") {
    $passworderror "Whoops! - you didn't enter a password.";
    include (
    "register.php");
    exit();
    }
    else {
    (
    rest of code
    It correctly detects if the fields are missing or not, but this only works if a password is not present. If someone enters something in the password box, the page goes ahead and submits itself, even if the other fields are blank! I can't understand why it is doing this, although I've probably made some obvious error!

    If anybody could help me out on this I'd be really grateful.

    Thanks in advance,
    Jon.
    Last edited by jonathanbull; 12-11-2004 at 12:55 PM.

  2. #2
    Join Date
    May 2004
    Location
    Colorado
    Posts
    948
    well, im not sure if this is the reason that the problem is there.. but it probably is

    instead of having if($this == ""){}

    you should do this

    if((!$thingone) || (!$thingtwo) || (!$thingthree)){

    if(strlen($field) <= 0){
    echo 'something wasnt input in there';
    }
    exit();
    }else{
    submit form
    }
    try that, either use strlen to check the length of the strings input or just check to see if they are not null by doing if($thing){
    echo 'thing exists';
    }else{
    echo 'thing doesnt exist';
    }

    have a go with that, post back if its still not working


    heh. i just looked at your code again and:

    its not going to work because with your
    password check section thats where you actually exit the script and include your page, with the rest all its going to do is echo out that there is somethign missing. so like i said, you have to have a whole if statement that encapsulates the rest of your checks, in that if statement you have to check if one thing is not set or another thing or another thing, then if any of those things are wrong, or dont exist in this case, it will go through and echo out the error messages for each field that you are missing. then after your last statement (the password check one, you close that } then have your include and exit(); which will exit the script if any of the required elements is missing


    hope you can understand that, stiil feeling a bit tired
    Last edited by WraithGuard; 12-11-2004 at 01:43 PM.


    Absolute Power, its the only way to roll!

  3. #3
    Join Date
    Jul 2004
    Location
    N29° 22.725' X W95° 6.452'
    Posts
    343
    the format should be like this:

    if ((!$this) || (!$that) || (!$theotherthing)) {
    header("Location: register.php");
    exit;
    }
    else {
    do something;
    }

    Also when using the header() function you must not output anything to the browser before you call it or it will not work right.

  4. #4
    Join Date
    Oct 2004
    Posts
    17
    Thanks mcarman, but this won't give an individual error for each missing field will it?

    you have to have a whole if statement that encapsulates the checks
    Reading this, I realise it is exactly what I was looking for. Could you please tell me how I would go about doing this?


    Thanks again for your help so far.
    Last edited by jonathanbull; 12-11-2004 at 02:38 PM.

  5. #5
    Join Date
    Jul 2004
    Location
    N29° 22.725' X W95° 6.452'
    Posts
    343
    no, it wont give your error message like that alone, i was more showing you how to redirect on error. but you can simply pass the error with the redirect string like this:


    if (!$name) {
    $error="No name entered.";
    header("Location: register.php?errormsg=$error");
    exit;
    }
    elseIf(!$pass) {
    $error="No password entered.";
    header("Location: register.php?errormsg=$error");
    exit;
    }
    else {...} and so on.

    then print out the $errormsg on the registration form.

    There is prolly a more efficient way to do this but if you are just learning its good to be able to see what is going on behind the scenes by coding it out.

    I prefer to use session vars to pass things like this but thats just me. any way this should give you an idea how to preceed.
    Last edited by mcarman; 12-11-2004 at 02:56 PM.

  6. #6
    Join Date
    Oct 2004
    Posts
    17
    Thank you mcarman.

    I originally managed to do this, but what I wanted to do is to echo every error on the registration page at once instead of only echoing one error.

    This is why I wanted to encapsulate the whole lot into one kind of statement.

    I hope I've explained this a bit better now!

    Thanks again.

  7. #7
    Join Date
    May 2004
    Location
    Colorado
    Posts
    948
    another thing that you could do, is have the form send to the same page as it is on, with a hidden field that gets set when you send the form, then you check to see if that hidden field is set, if it is, you go through check for errors, then have a function say, that will post the form to something, else if the hidden form is not set, it could just display the form


    Absolute Power, its the only way to roll!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •