I tried to test your code, but I get this error next to the labels and goto
Language feature not compatible with PHP version indicated in project
I have PHP 5.3.0.


From: Ethan Rosenberg [] 
Sent: 17 December 2010 06:39 PM
Subject: [PHP] Problems w/ goto

Dear List - 

I am sending this again since it does not seem to have posted. 

Dear List - 

Thank you with your excellent help in the past.  Here is another puzzler....

I am trying to write a program that can have two(2) independent forms 
in one PHP file.  When I run the code below [from PHP - A Beginner's 
Guide], to which I have added a second form, it freezes.  Without the 
goto statements, it runs.  When it does run, it displays both forms 
on one Web screen. What I desire is for the first form to be 
displayed, the data entered and then the second form displayed.  In 
an actual, not test program like this one, the data in the second 
form would be dependent on the first form. 

What did I do wrong? 

Thanks in advance. 

Here is the code: 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns=""; xml:lang="en" lang="en"> 
     <title>Project 4-4: Age Calculator</title> 
     <h2>Project 4-4: Age Calculator</h2> 
     // if form not yet submitted 
     // display form 

$ender = 0; 

         if($ender == 1) 
     if (!isset($_POST['dob'])) 

echo "  <form method=\"post\" action=\"agecalc2.php\">"; 
echo "  Enter your date of birth, in mm/dd/yyyy format: <br />"; 
echo "  <input type=\"text\" name=\"dob\" />"; 
echo "      <p>"; 
echo "  <input type=\"submit\" name=\"submit\" value=\"Submit\" />"; 
echo "  </form>"; 

goto begin; 
     // if form submitted 
     // process form input 
if (isset($_POST['cat'])) 
         goto purr; 
       // split date value into components 
       $dateArr = explode('/', $_POST['dob']); 

       // calculate timestamp corresponding to date value 
       $dateTs = strtotime($_POST['dob']); 

       // calculate timestamp corresponding to 'today' 
       $now = strtotime('today'); 

       // check that the value entered is in the correct format 
       if (sizeof($dateArr) != 3) { 
         die('ERROR: Please enter a valid date of birth'); 

       // check that the value entered is a valid date 
       if (!checkdate($dateArr[0], $dateArr[1], $dateArr[2])) { 
         die('ERROR: Please enter a valid date of birth'); 

       // check that the date entered is earlier than 'today' 
       if ($dateTs >= $now) { 
         die('ERROR: Please enter a date of birth earlier than today'); 

       // calculate difference between date of birth and today in days 
       // convert to years 
       // convert remaining days to months 
       // print output 
       $ageDays = floor(($now - $dateTs) / 86400); 
       $ageYears = floor($ageDays / 365); 
       $ageMonths = floor(($ageDays - ($ageYears * 365)) / 30); 
       echo "You are approximately $ageYears years and $ageMonths months
       goto meow; 

         if (!isset($_POST['dob'])) 
                 goto begin; 
     if (!isset($_POST['cat'])) 

echo "  <form method=\"post\" action=\"agecalc2.php\">"; 
echo "  <br /><br />Enter your kitten's name: <br />"; 
echo "  <input type=\"text\" name=\"cat\" />"; 
echo "  <p>"; 
echo "      <input type=\"submit\" name=\"submit\" value=\"Submit 
Kitten\" />"; 
echo "    </form>"; 

         $name_cat = $_POST['cat']; 

         echo "Your Kitten is $name_cat"; 
         $ender = 1; 
if ($ender == 0) 
         goto begin; 




MySQL 5.1  PHP 5  Linux [Debian (sid)]  

PHP General Mailing List ( 
To unsubscribe, visit: 


No virus found in this message.
Checked by AVG -
Version: 10.0.1170 / Virus Database: 1435/3323 - Release Date: 12/18/10

Reply via email to