Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Function and Array Problems - Help Needed!

    Hi,

    I've been spending the last few hours trying to figure out why my simple include won't work. It is a bunch of functions, and it isn't improperly written, and no errors are given. I am trying to make a multidimensional array by using validation functions and outputting the appended array so that I can call the multidimensional array full of errors to display them. Here's the code:

    include (sample function, not necessary to list them all):
    PHP Code:
    PHP Code:
    function checkAddress($address, &$errors) {
        if (
    strlen($address) < 4)
            
    $errors[] = array("address","Please enter your address!");

    actual script:
    PHP Code:
    PHP Code:
    error_reporting(E_ALL);
    include(
    'include.php');
        if (isset(
    $_POST['submit'])) {
            
    $firstname $_POST['firstName'];
            
    $lastname $_POST['lastName'];
            
    $address $_POST['address'];
            
    $address2 $_POST['address2'];
            
    $city $_POST['city'];
            
    $state $_POST['state'];
            
    $zipcode $_POST['zipCode'];
            
    $country $_POST['country'];
            
    $cardnumber $_POST['cardNumber'];
            
    $cardtype $_POST['cardType'];
            
    $expmonth $_POST['expMonth'];
            
    $expyear $_POST['expYear'];
            
    $cvv2code $_POST['cvv2code'];
            
    $amount $_POST['amount'];
            
    $errors = array();
            
    checkFirstName($firstname$errors);
            
    checkLastName($lastname$errors);
            
    checkAddress($address$errors);
            
    checkCity($city$errors);
            
    checkCountryAndState($state$country$errors);
            
    checkZipCode($zipcode$country$errors);
            
    checkCVV2($cvv2code$errors);
            
    checkAmount($amount$errors);
            
    checkCardType($cardtype$errors);
            
    checkCardNumber($cardnumber$errors);
            
    print_r($errors);
        } 
    ...and the screen just goes blank. No code, no nothing, and it has been doing it ever since I made the include. I have tried putting the code in the actual script, and I rewrote the whole thing, and nothing. I don't understand why it doesn't work. Any help is appreciated!

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Is it possible that the form isn't returning any errors? (eg you've filled out all the fields correctly)

    I know that sounds stupid, but I've done dumber stuff before....

    also try adding this line at the end:
    print count($errors);

    if that is a zero that proves nothing is in the array

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Its impossible because i submitted a completely blank form. I tried that, but nothing happens. The script almost "stops" after the include, and nothing happens. This shouldn't happen though.

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Can we see the 'include.php' code?

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #5
    New Coder
    Join Date
    Jun 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    function checkPassword($password$password2, &$errors) {
        if (
    strlen($password) < or strlen($password) > 20)
            
    $errors[] = array("password","Please enter a password that is 6-20 alphanumeric characters!");
        else if (
    $password !== $password2)
            
    $errors[] = array("password","The entered passwords do not match!");
        else if (!
    ctype_alnum($password))
            
    $errors[] = array("password","Your password can only contain numbers and letters.");
    }

    function 
    checkEmail($email, &$errors) {
        if (
    strlen($email) == 0)
            
    $errors[] = array("email","Please enter your email address!");
        else if (!
    preg_match('/^[a-z0-9.+_-]+@([a-z0-9-]+.)+[a-z]+$/i',$email))
            
    $errors[] = array("email","Email address is not valid!");
    }

    function 
    checkZipCode($zipcode$country, &$errors) {
        if (
    $country == "US") {
            if (
    strlen($zipcode) !== or !preg_match('/^[0-9][0-9][0-9][0-9][0-9]$/',$zipcode))
                
    $errors[] = array("zipcode","Please enter your 5 digit US zip code!");
        } else {
            if (empty(
    $zipcode))
                
    $errors[] = array("zipcode","Please enter your postal code");
        }
    }

    function 
    checkFirstName($firstname, &$errors) {
        if (!
    preg_match('/^[-A-Za-z]+$/',$firstname) or strlen($firstname) == 0)
            
    $errors[] = array("firstname","Please enter your first name!");
    }

    function 
    checkLastName($lastname, &$errors) {
        if (!
    preg_match('/^[-A-Za-z]+$/',$lastname) or strlen($lastname) == 0)
            
    $errors[] = array("lastname","Please enter your last name!");
    }

    function 
    checkCountryAndState($state$country, &$errors) {
        
    $nonstate = array("AB","BC","MB","NB","NL","NT","NS","NU","PE","SK","ON","QC");
        if (
    $state == "")
            
    $errors[] = array("state","Please enter your state/province!");
        else if (
    $country == "US" && in_array($state,$nonstate))
            
    $errors[] = array("state","Please enter your correct state!");
        else if (
    $country == "US" && $state == "Other")
            
    $errors[] = array("state","Please enter your correct state!");
        else if (
    $country == "CA" && !in_array($state,$nonstate))
            
    $errors[] = array("state","Please enter your correct province!");
    }

    function 
    checkAddress($address, &$errors) {
        if (
    strlen($address) < 4)
            
    $errors[] = array("address","Please enter your address!");
    }

    function 
    checkCity($city, &$errors) {
        if (!
    ctype_alpha($city) or strlen($city) == 0)
            
    $errors[] = array("city","Please enter your city!");
    }

    function 
    checkPhoneNumber($phone, &$errors) {
        if (
    strlen($phone) <= 9)
            
    $errors[] = array("phone","Please enter your phone number!");
        else if (
    ctype_digit($phone) && strlen($phone) == 10)
            
    $phone substr($phone,0,3)."-".substr($phone,3,3)."-".substr($phone,6,4);
        else if (
    strlen($phone) !== 12 or !preg_match('/^[0-9][0-9][0-9][-][0-9][0-9][0-9][-][0-9][0-9][0-9][0-9]$/',$phone))
            
    $errors[] = array("phone","Please enter a valid 10-digit phone number!");
    }

    function 
    checkRegion($other$state, &$errors) {
        if (
    $state == "Other" && strlen($other) == 0)
            
    $errors[] = array("other","Please enter your region!");
    }

    function 
    checkCVV2($cvv2code, &$errors) {
        if (
    strlen($cvv2code) < or !ctype_digit($cvv2code)
            
    $errors[] = array("cvv2code","Please enter your 3 or 4 digit CVV2 code.");
    }

    function 
    checkAmount($amount, &$errors) {
        if (
    strlen($amount) == 0)
            
    $errors[] = array("amount","There was a problem with the total of your order. Try starting over.");
    }

    function 
    checkCardType($cardtype, &$errors) {
        if (
    $cardtype == "")
            
    $errors[] = array("cardtype","Please select your credit card type.");
    }

    function 
    checkCardNumber($cardnumber, &$errors) {
        if (!
    ctype_digit($cardnumber))
            
    $errors[] = array("cardnumber","Please enter a valid credit card number.");


  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,151
    Thanks
    2
    Thanked 335 Times in 327 Posts
    Either $_POST['submit'] is not being set (you would need to post your form code to get help) or a fatal parse error is occurring.

    Check your web server log for errors and/or turn on full PHP error reporting (both display_errors and the E_ALL reporting level) in php.ini or a .htaccess file. Turning on error reporting with code in your script does not display fatal parse errors because parse errors prevent your script from ever executing and any code to change the error reporting won't ever get executed.

    Edit: The posted code produces the following error -
    Parse error: syntax error, unexpected T_VARIABLE in ...your path\include.php on line 76
    Last edited by CFMaBiSmAd; 08-15-2007 at 11:58 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Try returning $errors[] from each function, or making it global...

    Edit: I don't know enough to know whether or not that would work, so maybe an expert can set me straight, but if I were having this problem, I would do that because I don't know enough to know whether it is correct or not.


    HTH
    Dan
    Last edited by whizard; 08-16-2007 at 12:00 AM.
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #8
    New Coder
    Join Date
    Jun 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $_POST['submit'] is successful because it echoed "submit" (placed directly after that) when I was testing it. What is your line 76 consist of (yours may vary from mine). I will try returning each $errors[]; but I shouldn't have to make it global because its a reference in the function. Thanks

  • #9
    New Coder
    Join Date
    Jun 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I got it now after turning display_errors on. I don't understand why it was off, it defaults to on, but thanks.


  •  

    Posting Permissions

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