开发者

PHP is setting a variable to an array no matter what I do?

This is the weirdest bug I've ever encountered and I am at wits end here. It just started on the script even know the only thing I changed was running the capitalizing function on the first and last name variables.

The problem is with the "$lname" variable. I've got the script in debug, and I have it echoing out "$lname" throughout each process, and it's only after I set it to the _SESSION variable that it changes into an array. Nothing I do seems to work. Everytime the user returns to the form it unsets all the session vars, but I've even tried changing the name of "$_SESSION['reglname']; and I still get the same thing happening.

I'm at wits end here, and if you read through this you can see I've tried just about everything to force it through as a string. I guess I can edit the subsequent scripts to account for it being an array, but I'd rather figure out what the hells going on here so I can avoid it in the future! PLEASE HELP!

//Start session
session_start();

unset($_SESSION['ERRMSG_ARR']);

//Include database connection details
require_once("$DOCUMENT_ROOT/../SQLlogin.php");

//Array to store validation errors
$errmsg_arr = array();

//Validation error flag
$errflag = false;

//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
    die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
    die("Unable to select database");
}

//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
    $str = @trim($str);
    if(get_magic_quotes_gpc()) {
        $str = stripslashes($str);
    }
    return mysql_real_escape_string($str);
}

//Sanitize the POST values
$fname = clean($_POST['FirstName']);
$lname = clean($_POST['LastName']);
$email = clean($_POST['Email']);
$cemail = clean($_POST['ConfirmEmail']);
$bday = clean($_POST['BirthDay']);
$bmonth = clean($_POST['BirthMonth']);
$byear = clean($_POST['BirthYear']);

echo $lname;

//Capitalize first and last name
$fname = ucwords($fname);
$lname = ucwords($lname);

//Collate and format birthdate
if ($bmonth < 10){
    $bdate = clean("0".$bmonth."/".$bday."/".$byear);
}else{
    $bdate = clean($bmonth."/".$bday."/".$byear);
}

//Echo out vars to check
echo $fname."<br />".$lname;

//Server-side validations
if($fname == '' || strlen($fname) < 2 || strlen($fname) > 24 || strpbrk($fname, " ")) {
    $errmsg_arr[] = '*First name must be greater than 2 characters, less than 24, and contain no spaces!';
    $errflag = true;
}
if($lname == '' || strlen($lname) < 2 || strlen($lname) > 24 || strpbrk($lname, " ")) {
    $errmsg_arr[] = '*Last name must be greater than 2 characters, less than 24, and contain no spaces!';
    $errflag = true;
}
if(!ereg("[a-zA-Z]+", $fname, $lname)){
    $errmsg_arr[] = '*First and last name can contain only letters!';
    $errflag = true;
}
if ($email == '' || strlen($email) < 2 || strlen($email) > 32) {
    $errmsg_arr[] = '*Email address must be greater than 3 and less than 32 characters!';
    $errflag = true;
}
if ($cemail == '') {
    $errmsg_arr[] = '*Email address must be greater than 3 and less than 32 characters!';
    $errflag = true;
}
if ($email != $cemail) {
    $errmsg_arr[] = '*Email addresses do not match!';
    $errflag = true;
}
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
    $errmsg_arr[] = '*The email address entered appears to be invalid. Please enter a valid email address';
    $errflag = true;
}
if($bday == '') {
    $errmsg_arr[] = '*Birthday field left blank!';
    $errflag = true;
}
if($bmonth == '') {
    $errmsg_arr[] = '*Birth month field left blank';
    $errflag = true;
}
if($byear == '') {
    $errmsg_arr[] = '*Birth year field left blank';
    $errflag = true;
}
$year = date(Y);
if(($year - $byear) < 18){
    $errmsg_arr[] = '*You must be 18 years or older to register as a Hoppr client!';
    $errflag = true;
}
$allowed_age = 18;
$bdatecheck = strtotime($byear.'-'.$bmonth.'-'.$bday);
$age = (time()-$bdatecheck)/31536000;
if($age >= $allowed_age) {

}else{
    $errmsg_arr[] = '*You must be开发者_StackOverflow 18 years or older to register as a Hoppr client!';
    $errflag = true;
}

//If there are input validations, redirect back to the registration form
if($errflag) {
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
    session_write_close();
    header("location: http://www.thehoppr.com/clients/registration.php");
    exit();
}

echo $_SESSION['reglname'];

//Set registration session vars
$_SESSION['regstep'] = (int) 0;
$_SESSION['regfname'] = (string) $fname;
(string) $_SESSION['reglname'] = (string) $lname;
$_SESSION['regemail'] = (string) $email;
$_SESSION['regbdate'] = (string) $bdate;

echo $_SESSION['reglname'];

//Perform the email check query
$checkqry = "SELECT * FROM clients WHERE email='".mysql_real_escape_string($email)."'";
$checkresult = mysql_query($checkqry);
$checkAry = mysql_fetch_array($checkresult, MYSQL_ASSOC);
if (empty($checkAry)){
    //No email found, send user to step 2
    $_SESSION['regstep'] = (int) 2;
}else{
    //Dupl email found, check for Hoppr registration
    $isReg = $checkAry['isReg'];
    if ($isReg == 0) {
        global $checkAry;
        //Email found but not registered. Send user to Facebook merge page
        $_SESSION['regstep'] = (int) 1;
        $_SESSION['regfbname'] = $checkAry['firstname']." ".$checkAry['lastname'];
        $_SESSION['regfbpic'] = $checkAry['imgURL'];
        $_SESSION['regfbid'] = $checkAry['facebookID'];
        $_SESSION['regfbbday'] = $checkAry['birthday'];
    }else{
        //Email found and is registered. Ask user for a different email
    }
}


Here's your problem:

if(!ereg("[a-zA-Z]+", $fname, $lname)){

I think you want:

if(!ereg("[a-zA-Z]+", $fname.$lname)){

The Ereg will store matches in param 3.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜