Jump to content


Photo

Constants


  • Please log in to reply
5 replies to this topic

#1 Lee

Lee
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 21 September 2006 - 06:01 PM

i am learning from a book, & it has not illustrated how constants should be written.
I wrote this code..

<html>
<head><title>Constants</title></head>
<body>
<?php /* this is a script using a simple constant to make a calculation*/
define("TRADE_DISCOUNT", 0.75);
$Amount= 20.00;
$Discount= 2.50;
$Trade= $Amount * TRADE_DISCOUNT;

echo "A cheap guitar costs {$Amount}. You can get a discount of {$Discount}.<br />
     When you buy at trade price though, you get it at {$Trade}.

?>
</body>
</html>

But I get this error..

Parse error: parse error, unexpected $end in C:\wamp\www\constants.php on line 15


I don't understand about line 15, thats just the closing html tag, but obviously I'm doing something wrong.
Can anyone enlighten me please?

Thanks  :)

#2 eric1235711

eric1235711
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts
  • LocationSão Paulo - Brazil

Posted 21 September 2006 - 06:03 PM

you forgot to close the string:
<?php
// ...
echo "A cheap guitar costs {$Amount}. You can get a discount of {$Discount}.<br />
     When you buy at trade price though, you get it at {$Trade}. "; // <<<---------- HERE

?>

Programming is like building your own universe...
But let me ask you something:
Your world... It´s cool? Or it sucks?

#3 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 21 September 2006 - 06:04 PM

when you end your echo, you need  ";  not just a period

#4 Lee

Lee
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 21 September 2006 - 06:06 PM

aaaahh, a rookie mistake. (I just started last night).

Thanks guys!  ;D

#5 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 21 September 2006 - 06:07 PM

when you end your echo, you need  ";  not just a period


Depends. You do not need the semi-colon if it is the last thing, but it is good practice to always add it.

#6 Lee

Lee
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 21 September 2006 - 08:16 PM

Ok I'm into another pickle.
This code..
<?php /* this is a script using a simple constant to make a calculation*/
define("TRADE_DISCOUNT", 0.75);
$Amount= 20.00;
$Discount= 2.50;
$Trade= $Amount * TRADE_DISCOUNT;

echo "A cheap guitar costs {$Amount}. You can get a discount of {$Discount}.<br />
     When you buy at trade price though, you get it at {$Trade}. <p>";
	 
echo "We can buy it for £",TRADE_DISCOUNT;
?>

<?php
/* this is the line & file constants (line tells you hat line it is on, File tells you the path to the file*/

echo __LINE__;

echo __FILE__;
?>
..produces this in the browser

A cheap guitar costs 20. You can get a discount of 2.5.
When you buy at trade price though, you get it at 15.

We can buy it for £0.75 20






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users