Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2003, 11:47 PM
Registered User
 
Join Date: Dec 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with function...



Hey Guys, I need help with the function...if any of you already run the Namllu Holiday Booking Form (From Beginning PHP) -->holiday.html and work with the function on chapter 6 page 199 please help me...b/c my function does not work properly. Every time I run the program it only shows the default "Go back and do it again" without calculating the function itself.

Thank you for your help!!
 
Old December 17th, 2003, 04:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Many of us don't have the book, nor do we have the source code downloaded. It'd be easiest for me to help you if you paste the relevant code and describe the application a little more.

I have some questions for you to answer, too -- have you been able to successfully run other scripts from the book, or is this your first attempt? What are the values of the register_globals and error_reporting PHP configuration directives? (you can check these values by running a phpinfo() script, and you can set them in php.ini).



Take care,

Nik
http://www.bigaction.org/
 
Old December 18th, 2003, 01:02 AM
Registered User
 
Join Date: Dec 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Nik, thx for the reply. Here is the code

HTML

<html>
<head></head>
<body>
<b>Namllu Holiday Booking Form</b>
<Form Method=Get Action="holiday3.php">
Where do you want to go on holiday?
<br>
<br>
<input name="Destination" type="Radio" value="Praque">
Praque
<br>
<input name="Destination" type="Radio" value="Barcelona">
Barcelona
<br>
<input name="Destination" type="Radio" value="Vienna">
Vienna
<br>
<br>
What grade of hotel do you want to stay at?
<br>
<br>
<input name="Grade" type="Radio" value="Three">
Three Star
<br>
<input name="Grade" type="Radio" value="Four">
Four Star
<br>
<br>
<input type=submit>
</form>
</body>
</html>

holiday3.php codes...

<html>
<head></head>
<body>
<?php
function Calculator($Price, $CityModifier, $StarModifier)
{
return $Price=$Price*$CityModifier*Starmodifier;
}
$Price=500;
$StarModifier=1;
$CityModifier=1;
$DestGrade=$Destination.$Grade;
switch($DestGrade){
  case "BarcelonaThree":
  $CityModifier=2;
  break;
  case "BarcelonaFour":
  $CityModifier=2;
  $StarModifier=2;
  break;
  case "ViennaThree":
  $CityModifier=3.5;
  break;
  case "ViennaFour":
  $CityModifier=3.5;
  $StarModifier=2;
  break;
  case "PraqueThree":
  break;
  case "PraqueFour":
  $StarModifier=2;
  break;
  default:
  $CityModifier=0;
  echo ("Go back and do it again");
}
if ($CityModifier<>0)
{
echo "The cost for a week in $Destination is "."$".
Calculator($Price,$CityModifier,$StarModifier);
}
?>
</body>
</html>

Thx Nik. I've checked my register_global=on and I've done a couple of scripts earlier. Everything works fine until this one came...

Thanks once again!
 
Old December 18th, 2003, 04:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Two problems exist in holiday3.php. Here's your code:

Quote:
quote:
function Calculator($Price, $CityModifier, $StarModifier)
{
return $Price=$Price*$CityModifier*Starmodifier;
}
Both problems are on the same line. The first is that you don't have a dollar sign in front of "Starmodifier" in your return statement, so PHP thinks that you're looking up a defined constant. Since Starmodifier is NOT a named constant, PHP treats it as a string. PHP tries to convert that string to a number because you're using it in a mathematical expression (multiplication). Since the string "Starmodifier" doesn't contain any digits, it gets converted to zero. That's why all your prices are zero.

Second, your variable name is "StarModifier". PHP variable names are case-sensitive, so $StarModifier is __NOT__ the same thing as $Starmodifier.

Here's the fixed code:

function Calculator($Price, $CityModifier, $StarModifier)
{
   return $Price * $CityModifier * $StarModifier;
}


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
function keyvanjan ASP.NET 2.0 Professional 1 September 19th, 2007 10:22 AM
How to use Function akumarp2p SQL Server 2000 1 May 28th, 2007 05:04 AM
send variable in function to another function schoolBoy Javascript How-To 6 March 3rd, 2007 09:16 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.