Unexpected End?

Whenever I try to run a register script(process.php) from a pre-processed form, I always get this error.

Parse error: syntax error, unexpected $end in /dir/check.inc on line 119

Check.inc is a file that is a form checking file for process.php … this is the file itself

[code]<?php
//USERNAME CHECK

function usercheck($usercheckname)
{

if(!ereg("^[A-Za-z -]+$",$usercheckname))
{
echo “Invalid Username. Try again.”;
die();
}
else
{
echo “Username Success”;
return $usercheckname;
}
}

//PASSWORD CHECK

function pwchecker($pwcheckname)
{

if(!ereg("^[A-Za-z -]+$",$pwcheckname))
{
die(“Parse error in your username, please press back and check”);
}
else
{
echo “Password Success”;
return $pwcheckname;
}

}

//EMAIL CHECK
function check_email_address($email) {

// First, we check that there’s one @ symbol, and that the lengths are right

if (!ereg("[^@]{1,64}@[^@]{1,255}", $email)) {

// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.

die(“Email error, please go back and check.”);

}

// Split it into sections to make life easier

$email_array = explode("@", $email);

$local_array = explode(".", $email_array[0]);

for ($i = 0; $i < sizeof($local_array); $i++) {

if (!ereg("^(([A-Za-z0-9!#$%&’*+/=?^_{|}~-][A-Za-z0-9!#$%&'*+/=?^_{|}~.-]{0,63})|("[^(|")]{0,62}"))$", $local_array[$i])) {

die(“Email error, please go back and check.”);

}

}

if (!ereg("^[?[0-9.]+]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name

$domain_array = explode(".", $email_array[1]);

if (sizeof($domain_array) < 2) {

die(“Email error, please go back and check.”); // Not enough parts to domain

}

for ($i = 0; $i < sizeof($domain_array); $i++) {

if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {

die(“Email error, please go back and check.”);

}

}

}
echo “Email Success”;
return $email;

}

//GENDER CHECK

function gencheck($gencheck)
{

if(!ereg("(male|female)",$gencheck))
{
die(“Parse error in your username, please press back and check again”);
}
else
{
echo “Gender Success”;
return $gencheck;
}

//AGE CHECK

function agecheck($agecheck)
{

if(!ereg("[0-9]+",$agecheck)) {
die(“Parse error in your DOB, please press back and check again”);
} else {
echo “Age Success”;
return $agecheck;
}

}
?>[/code]

Help is appreciated.

I took the liberty to “Reformat” your code and when I did the problem became perfectly clear (See code below)

[php]

<?php //USERNAME CHECK function usercheck($usercheckname) { if(!ereg("^[A-Za-z -]+$",$usercheckname)) { echo "Invalid Username. Try again."; die(); } else { echo "Username Success"; return $usercheckname; } } //PASSWORD CHECK function pwchecker($pwcheckname) { if(!ereg("^[A-Za-z -]+$",$pwcheckname)) { die("Parse error in your username, please press back and check"); } else { echo "Password Success"; return $pwcheckname; } } //EMAIL CHECK function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("[^@]{1,64}@[^@]{1,255}", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. die("Email error, please go back and check."); } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~.-]{0,63})|("[^(\|")]{0,62}"))$", $local_array[$i])) { die("Email error, please go back and check."); } } // Check if domain is IP. If not, it should be valid domain name if (!ereg("^[?[0-9.]+]?$", $email_array[1])) { $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { die("Email error, please go back and check."); // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { die("Email error, please go back and check."); } } } echo "Email Success"; return $email; } //GENDER CHECK function gencheck($gencheck) { if(!ereg("(male|female)",$gencheck)) { die("Parse error in your username, please press back and check again"); } else { echo "Gender Success"; return $gencheck; } } //<---------------------------------- This Brace was missing //AGE CHECK function agecheck($agecheck) { if(!ereg("[0-9]+",$agecheck)) { die("Parse error in your DOB, please press back and check again"); } else { echo "Age Success"; return $agecheck; } } ?>[/php]

It helps to develp a style of code writing that makes the flow very clear. You are “Nesting” a lot of loops and control structures that make it difficult to keep track of all the opening and closing braces. Additionally it makes the code hard to follow. As I was doing the reformat (for my own readability concerns) I noticed you were missing a curly brace (noted in the above code).

Additionally, as you wrote the code you changed styles of how you “Bracketed” your code. For example"

If (condition)
{
some code
}
else
{
some more code 
}

Then later on you had

If (condition) {
some code
} else {
some more code 
}

Either style is ok but you should be consistent. Tabbing and additional “Whitespace” would help too. in reference to Indenting. Not necessarily in between lines. Near the end of your code you seemed to put a carriage return in after every line. That only served to make the code more difficult to read.

I am not saying all this to chastise you. But had you been consistent (for one) that error might have been more obvious (as it was to me when I reformatted). It will also help others reading your code, whether it’s someone having to maintain your code later or someone like me on a forum trying to help.

That being said, I found that ONE error and did not look any further for subsequent problems. So there might be more. Make the correction and see if something else pans out.

Sponsor our Newsletter | Privacy Policy | Terms of Service