RE: [PHP] Problems w/ goto

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

  _____  

From: Ethan Rosenberg [mailto:ethros@xxxxxxxxxxxxx] 
Sent: 17 December 2010 06:39 PM
To: php-db-lists.php.net; php-general@xxxxxxxxxxxxx
Subject: [PHP] Problems w/ goto



Dear List - 

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

Ethan 
+++++++ 
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" 
    "DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en"> 
   <head> 
     <title>Project 4-4: Age Calculator</title> 
   </head> 
   <body> 
     <h2>Project 4-4: Age Calculator</h2> 
<?php 
     // if form not yet submitted 
     // display form 

$ender = 0; 
begin: 

         if($ender == 1) 
                 exit(); 
     if (!isset($_POST['dob'])) 
     { 
start1: 

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 
     } 
else 
     { 
starter: 
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
old."; 
       goto meow; 
  } 

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>"; 

} 
else 
{ 
purr: 
         $name_cat = $_POST['cat']; 

         echo "Your Kitten is $name_cat"; 
         $ender = 1; 
} 
if ($ender == 0) 
         goto begin; 
first_step: 
?> 

   </body> 
</html> 

============ 

Ethan 

MySQL 5.1  PHP 5  Linux [Debian (sid)]  



-- 
PHP General Mailing List (http://www.php.net/) 
To unsubscribe, visit: http://www.php.net/unsub.php 

  _____  

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux