1

Possible Duplicate:
Form Submits to white page?

So on my page, index.php, there is a registration form. The form checks for errors, and if theres errors, it doesn't do the query, however, if there is no errors, it is supposed to submit the query.

When a user types in all their info, and presses Register, the form submits correctly and displays all the errors that they did.

HOWEVER, if there is NO errors, the form submits to a white page, and the query is not executed.

The form uses method="POST", just a heads up.. Here's the PHP.

$errors=array();
if (isset($_POST['register'])) {
    if ($_POST['register']) {
        $rUsername=$_POST['usernamei'];
        $rPassword=$_POST['passwordi'];
        $rConfirm=$_POST['confirm'];
        $rEmail=$_POST['email'];
        $rProvider=$_POST['provider'];
        $rFirst=$_POST['firstname'];
        $rLast=$_POST['lastname'];
        $rRefer=$_POST['refer'];
        $allow=array('_', '-', '.');
        include 'mysqlcon.php';

        if (!$rUsername) {
            array_push($errors, 'You must enter a username!');
        } else {
            if (!ctype_alnum($rUsername)) {
                array_push($errors, 'Your username must be alphanumeric!');
            } else {
                $checkexist=(mysql_numrows(mysql_query(
                    "SELECT * FROM users WHERE username='".$rUsername."'")))
                        or die(mysql_error());
                if (!$checkexist==0) {
                    array_push($errors, 'This username is taken!');
                }
            }
            if (strlen($rUsername)>15) {
                array_push($errors, 'Your username is greater than 15 characters long!');
            }
        }

        if (!$rPassword) {
            array_push($errors, 'You must enter a password');
        } else {
            if (!ctype_alnum($rPassword)) {
                array_push($errors, 'Sorry, but passwords must be alphanumeric!');
            }
        }

        if (!$rConfirm) {
            array_push($errors, 'You must confirm your password!');
        } else {
            if (!$rConfirm==$rPassword) {
                array_push($errors, 'Your password did not match the confirmation!');
            }
        }

        if (!$rEmail) {
            array_push($errors, 'You did not enter an email!');
        } else {
            if (!ctype_alnum(str_ireplace($allow, '', $rEmail))) {
                array_push($errors, 'Your email contained some invalid characters!');
            }
        }

        if (!$rProvider) {
            array_push($errors, 'You did not enter an email!');
        } else {
            if (!ctype_alnum(str_ireplace($allow, '', $rProvider))) {
                array_push($errors, 'Your email provider contained some invalid characters!');
            }
        }

        if (!$rFirst) {
            array_push($errors, 'You did not enter your first name!');
        } else {
            if (!ctype_alnum(str_ireplace($allow, '', $rFirst))) {
                array_push($errors, 'Your first name can only contain alphanumeric characters!');
            }
        }

        if (!$rLast) {
            array_push($errors, 'You did not enter your last name!');
        } else {
            if (!ctype_alnum(str_ireplace($allow, '', $rLast))) {
                array_push($errors, 'Your first name can only contain alphanumeric characters!');
            }
        }

        if ($rRefer) {
            if (!ctype_alnum(str_ireplace($allow, '', $rRefer))) {
                array_push($errors, 'Your friend\'s name can only be alphanumeric!');
            }
        }

    }
}

if (empty($errors)) {
    $isError="1";
} else {
    $isError="2";
}

20 minutes later

Just found out that it submits a query with blank fields when a user goes to index.php.. I'm so stressed out right now. :(

Edit

Just turned on error reporting- no errors.

Edit II

This is the query code:

if ($isError=="1") {
$userip=$_SERVER['REMOTE_ADDR'];
$today=date('Y').'/'.date('m').'/'.date('d');
$temail=$rEmail.'@'.$rProvider;
$newuser = "INSERT INTO users (username, password, firstname, lastname, email, date, ip)
VALUES  ('$rUsername', '$rPassword', '$rFirst', '$rLast', '$temail', '$today', '$userip')";
mysql_query($newuser);
}

Edit III* Alright, so I just experimented a little, and it seems as if any code below the if statement for checking if $_POST['register'] is there DOES NOT EXECUTE.. However, when there is user registration errors like 'You must enter a username!', code executes..

Community
  • 1
  • 1
Seth
  • 2,043
  • 5
  • 20
  • 23
  • don't worry too much, shouldn't be too tough a debug, what does the form look like, and the server side processing code? blank page could be indicative of an error there, try throwing in a print_r($_POST[]) at the top of the page to see if the variables are received. – Brandon Frohbieter Feb 26 '11 at 17:46
  • Okay! So I know that on the white page, this is where the $_POST variables are.. but it doesn't display any content! – Seth Feb 26 '11 at 17:48
  • Enable error_reporting if you get a blank page. – mario Feb 26 '11 at 17:49
  • Turned it on. No errors. Still a white page. – Seth Feb 26 '11 at 17:51
  • @Seth: It looks like a critical part of the code is still missing. Where's the part that does the querying after the errors? – mellamokb Feb 26 '11 at 17:55
  • @Seth: Are you sure you've turned on error reporting completely? It can be a chore to get it working, because PHP is careful to keep from revealing information to the user. Make a simple page with an obvious syntax error (like an invalid method call) and make sure the error shows. – mellamokb Feb 26 '11 at 17:58
  • I put this above $errors=array(); ini_set('display_errors', 'On'); error_reporting(E_ALL); – Seth Feb 26 '11 at 17:59
  • @Seth: That may still not let errors show if there is a syntax error, because the parser will error before it ever reaches those two lines of code. Try setting error mode in the php.ini in your PHP configuration and re-running the page. Thanks! – mellamokb Feb 26 '11 at 18:00
  • I don't seem to have a clue where my php.ini file is located.. at all. You don't see an error with my code? – Seth Feb 26 '11 at 18:02
  • @Seth: I can't find anything wrong at first glance. It will be much, MUCH easier to find with an error message and a line number. As far as `php.ini`, that depends on your installation. Did you install `PHP` yourself? Are you using a package like `WAMP`? Is this Windows or *nix-based? – mellamokb Feb 26 '11 at 18:13
  • @Seth: Also see http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php and http://www.wallpaperama.com/forums/how-to-display-php-errors-in-my-script-code-when-display-errors-is-disabled-t453.html for more info. – mellamokb Feb 26 '11 at 18:13
  • My server is a GoDaddy server.. so I really don't know. – Seth Feb 26 '11 at 18:16
  • @Seth: Can you print out `$newuser` using `echo $newuser;` before the query runs? Perhaps that will give a clue.. – mellamokb Feb 26 '11 at 18:17
  • Take a look at Edit III. Just posted it. – Seth Feb 26 '11 at 18:21
  • What about the form? It looks as though `$_POST[register]` is either false (or false-like), or not set. – Mike Caron Feb 26 '11 at 18:24
  • I did print_r($_POST); at the top of my code, and all the POST variables are being submitted successfully. – Seth Feb 26 '11 at 18:25
  • are you sure that what you say in edit III is true? – Brandon Frohbieter Feb 26 '11 at 18:38
  • It seems like it. I'll put a simple echo on the last line of the if {}. – Seth Feb 26 '11 at 18:39
  • Yep, it's true. Nothing below the last } executes. – Seth Feb 26 '11 at 18:40
  • Is 'isError' are correctly set in all cases (try yo var_dump() it)? Is SQL query correct (try to add 'or die(mysql_error())' or something elese)? Is control flow reaching 'if ($isError=="1")' statement at all? – Olegas Feb 26 '11 at 18:42
  • Should I go with the old fashion style of just putting echo on every line and see where it stops? – Seth Feb 26 '11 at 18:44
  • If where are no any posting (empty $_POST['regsiter']) when $errors are empty and isError == 1. Then code flows in query submission but not any data is filled in, nor sql connection is established (as mysqlconn.php is included only then 'register' is set). May be the root of the error is in this erroneous control flow logic? – Olegas Feb 26 '11 at 18:46
  • mysqlcon.php is the connection to the database. Do not worry about this. I'll try my echo method and let you know what happened. – Seth Feb 26 '11 at 18:47
  • OKAY. So I think I found the problem.. I did a bunch of echoing on every line.. and the echoing stopped here: if (!ctype_alnum($rUsername)) { array_push($errors, 'Your username must be alphanumeric!'); – Seth Feb 26 '11 at 18:50
  • I didn't find the problem.. That's just where code stopped executing. I'm still lost. – Seth Feb 26 '11 at 19:01
  • Is execution comes to line with $checkexist? – Olegas Feb 26 '11 at 19:36
  • Can you rephrase the question with better grammar? I couldn't really understand it. – Seth Feb 26 '11 at 19:55
  • Oh... sorry... is '!ctype_alnum($rUsername)' executed or not? Is execution stops on this statement or after it, in 'else' block or at 'array_push'? – Olegas Feb 26 '11 at 19:59
  • Why are you using single quotes surrounding your SQL values? – Pr0no Feb 26 '11 at 19:52
  • It just stopped executing AFTER that line. I believe the next line is what broke. Not sure. – Seth Feb 26 '11 at 20:21

0 Answers0