Jump to content

Recommended Posts

i have no clue why this is happening. all the research i've done shows that this error occurs when coding in an OOP fashion. here's my error:

 

Fatal error: Cannot access empty property in /var/www/piratebeachhouse/validate.php on line 51

 

and here's my code

 

validate.php

<?php
    function valName($string)
    {
        $string = trim($string);
        if (!preg_match('/^[a-zA-Z ]+$/', $string)) {
            $_SESSION['error']['fullname'] = 1;
        }
    }

    function valParty($string)
    {
        $string = trim($string);
        if (!preg_match('/^[0-9]+$/', $string)) {
            $_SESSION['error']['numparty'] = 1;
        }
    }

    function valNights($string)
    {
        $string = trim($string);
        if (!preg_match('/^[0-9]+$/', $string)) {
            $_SESSION['error']['numnights'] = 1;
        }
    }

    function valDate($string)
    {
        $string = trim($string);
        if (!preg_match('/0?([1-9]?|1[0-2]?)[-\/.](0?[1-9]|[12][0-9]|3[01])[-\/.]20\d\d/', $string)) {
            $_SESSION['error']['date'] = 1;
        }
    }

    function valPhone($string)
    {
        $string = trim($string);
        if (!preg_match('/^1?[-.(]?(\d{3})[-.)]?(\d{3})[-.]?(\d{4})/', $string)) {
            $_SESSION['error']['phone'] = 1;
        }
    }

    function valEmail($string)
    {
        if (!preg_match('/^[A-Za-z0-9._-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/', $string)) {
            $_SESSION['error']['email'] = 1;
        }
    }

   /* set session variable to show form has been submitted */
    if (isset($_POST)) {
        foreach ($_POST as $k -> $v) {           //<----   LINE 51
            $_SESSION['submitted'][$k] = $v;
        }
    }
    /* run validation functions */
    valName($_POST['fullname']);
    valPhone($_POST['phone']);
    valEmail($_POST['email']);
    valDate($_POST['arrivaldate']);
    valNights($_POST['numnights']);
    valParty($_POST['numparty']);

    /* redirect to index.php if erroneous input */
    if (count($_SESSION['error'] < 0)) {
        header('Location: index.php');
        exit;
    }

    $body .= 'Full Name: '. $fullname ."\n";
    $body .= 'Phone: '. $phone ."\n";
    $body .= 'Email: '. $email ."\n";
    $body .= 'Date: '. $date ."\n";
    $body .= 'Number of Nights: '. $numnights ."\n";
    $body .= 'Number in Party: '. $numparty ."\n";

    mail('test@mail.com', 'website form bookdate', $body);

    header('Location: index.php');
?>

 

as you may have noticed, this is a validation script that is called upon whenever someone submits a form from index.php. can anybody help?

Link to comment
https://forums.phpfreaks.com/topic/79311-cannot-access-empty-property/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.