boo_lolly Posted November 28, 2007 Share Posted November 28, 2007 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('[email protected]', '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 More sharing options...
MadTechie Posted November 28, 2007 Share Posted November 28, 2007 change foreach ($_POST as $k -> $v) { //<---- LINE 51 to foreach ($_POST as $k => $v) { //<---- LINE 51 simple typo Link to comment https://forums.phpfreaks.com/topic/79311-cannot-access-empty-property/#findComment-401602 Share on other sites More sharing options...
boo_lolly Posted November 29, 2007 Author Share Posted November 29, 2007 thanks MadTechie! it's been a while since i've coded in php. i appreciate it! Link to comment https://forums.phpfreaks.com/topic/79311-cannot-access-empty-property/#findComment-402286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.