p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Please, help me!! Form "holiday.html"!


Message #1 by "bezier" <bezier_x@l...> on Wed, 2 Oct 2002 23:11:23
Hi!
I tryed the exercise about if and elseif instrunctions in chapter 4 ( in  
the italian version of the book )named holiday.html, but the result is 0!
Can you help me?

Thank you

Lara (Italy)
Message #2 by "Nikolai Devereaux" <yomama@u...> on Wed, 2 Oct 2002 15:06:14 -0700
> I tryed the exercise about if and elseif instrunctions in chapter 4 ( in
> the italian version of the book )named holiday.html, but the result is 0!
> Can you help me?

Can you post your code?  I have a feeling that you're testing the value of a
variable that is not set...

Ciao,

Nik
(I wish I was in Italy)

Message #3 by "bezier" <bezier_x@l...> on Thu, 3 Oct 2002 09:18:15
> THIS IS holiday.php FILE

<html>
<body>
<?php
$Prezzo=500;
$StarModifier=1;
$CityModifier=1;

if ($Categoria=="Tre")
{
   if ($Destinazione=="Barcellona")
   {
       $CityModifier=2;
       $Prezzo = $Prezzo * $Citymodifier;
       echo "Il costo per una settimana in $Destinazione  $Prezzo";
   }
   
   elseif ($Destinazione=="Vienna")
   {
      $CityModifier=3.5;
       $Prezzo = $Prezzo * $Citymodifier;
       echo "Il costo per una settimana in $Destinazione  $Prezzo";
   }
   
   elseif ($Destinazione=="Praga")
   {
     
       $Prezzo = $Prezzo * $Citymodifier;
       echo "Il costo per una settimana in $Destinazione  $Prezzo";
   }

   else
   { 
       echo ("Non hai inserito un valore per la destinazione, torna 
indietro e riprova");

    }
}

elseif ($Categoria=="Quattro")
{     
      $StarModifier=2;
       if ($Destinazione=="Barcellona")
     {
       $CityModifier=2.5;
       $Prezzo = $Prezzo * $CityModifier * StarModifier;
       echo "Il costo per una settimana in $Destinazione  $Prezzo";
     } 

    
      elseif ($Destinazione=="Vienna")
     {
      
      $CityModifier=4;
      $Prezzo = $Prezzo * $CityModifier * StarModifier;
       echo "Il costo per una settimana in $Destinazione  $Prezzo";
     }
    
       elseif ($Destinazione=="Praga")
     {
       $Prezzo = $Prezzo * $CityModifier * StarModifier;
       echo "Il costo per una settimana in $Destinazione  $Prezzo";
     }

else

   {

  echo ("Non hai inserito un valore per la destinazione, torna indietro e 
riprova");
   }

}
else
 {

  echo ("Non hai inserito un valore per la categoria, torna indietro e 
riprova");
   }

?>
</body>
</html>

AND THIS IS holiday.html file associated

<html>
<body>
<b> Prenota le tue vacanze </b>
<form method=post action="holiday.php">
Dove vuoi andare in vacanza?
<br><br>
<input name="Destinazione" type="Radio" value="Praga"> Praga
<br>
<input name="Destinazione" type="Radio" value="Barcellona"> Barcellona
<br>
<input name="Destinazione" type="Radio" value="Vienna"> Vienna
<br><br>
Scegli la categoria di albergo che preferisci
<br><br>
<input name="Categoria" type="Radio" value="Tre"> Tre stelle
<br>
<input name="Categoria" type="Radio" value="Quattro"> Quattro stelle
<br><br>
<input type=submit value="Invia">
</form>
</body>
</html>


BYE BYE 
THANKS


Can you post your code?  I have a feeling that you're testing the value 
of a
variable that is not set...

Ciao,

Nik
(I wish I was in Italy)

Message #4 by "Nikolai Devereaux" <yomama@u...> on Thu, 3 Oct 2002 10:06:09 -0700
Ciao Lara,

Do you have register_globals = on in your PHP.ini file?  If not, you need to
use the $_GET or $_POST arrays to access your variables.

That is, in holiday.php, do this:

if($_POST['Categoria'] == 'Tre')
{
   if($_POST['Destinazione'] == 'Barcellona')
   {
     ...
   }
}



This has been the most frequently posted problem on this list.  There should be
lots of information in the archives; just search for "register_globals" in the
archives.

Also, there's a section in the manual about register_globals:
  http://it.php.net/security.register_globals


Hope this helps!

Nik

Message #5 by "bezier" <bezier_x@l...> on Fri, 4 Oct 2002 17:56:46
> Thank you Nikolai!
Now it's all right!

:-))




Ciao Lara,

Do you have register_globals = on in your PHP.ini file?  If not, you need 
to
use the $_GET or $_POST arrays to access your variables.

That is, in holiday.php, do this:

if($_POST['Categoria'] == 'Tre')
{
   if($_POST['Destinazione'] == 'Barcellona')
   {
     ...
   }
}



This has been the most frequently posted problem on this list.  There 
should be
lots of information in the archives; just search for "register_globals" 
in the
archives.

Also, there's a section in the manual about register_globals:
  http://it.php.net/security.register_globals


Hope this helps!

Nik


  Return to Index