Lee Posted September 21, 2006 Share Posted September 21, 2006 i am learning from a book, & it has not illustrated how constants should be written.I wrote this code..[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>[/code]But I get this error..[quote]Parse error: parse error, unexpected $end in C:\wamp\www\constants.php on line 15[/quote]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 :) Link to comment https://forums.phpfreaks.com/topic/21555-constants/ Share on other sites More sharing options...
eric1235711 Posted September 21, 2006 Share Posted September 21, 2006 you forgot to close the string:[code]<?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?>[/code] Link to comment https://forums.phpfreaks.com/topic/21555-constants/#findComment-96178 Share on other sites More sharing options...
Wintergreen Posted September 21, 2006 Share Posted September 21, 2006 when you end your echo, you need "; not just a period Link to comment https://forums.phpfreaks.com/topic/21555-constants/#findComment-96180 Share on other sites More sharing options...
Lee Posted September 21, 2006 Author Share Posted September 21, 2006 aaaahh, a rookie mistake. (I just started last night).Thanks guys! ;D Link to comment https://forums.phpfreaks.com/topic/21555-constants/#findComment-96181 Share on other sites More sharing options...
Daniel0 Posted September 21, 2006 Share Posted September 21, 2006 [quote author=Wintergreen link=topic=108947.msg438834#msg438834 date=1158861877]when you end your echo, you need "; not just a period[/quote]Depends. You do not need the semi-colon if it is the last thing, but it is good practice to always add it. Link to comment https://forums.phpfreaks.com/topic/21555-constants/#findComment-96182 Share on other sites More sharing options...
Lee Posted September 21, 2006 Author Share Posted September 21, 2006 Ok I'm into another pickle.This code..[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__;?>[/code]..produces this in the browser[quote]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 [/quote] Link to comment https://forums.phpfreaks.com/topic/21555-constants/#findComment-96307 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.