Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Php Problem Error Message, I'm working from a book
NilsC
post Jan 14 2005, 01:42 AM
Post #1


To Err Is Human, To Forgive Divine
Group Icon

Group: Members
Posts: 558
Joined: 24-December 04
From: http://www.ultimatekayakfishing.com/
Member No.: 1,871



I get this error message when I try to view a small webpage.
QUOTE
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/nilsc/public_html/bobs/processorder.php on line 27

Line 27 is in this php part:
CODE
<?php
echo '<p>Order processed.</p>';
echo $tireqty. ' tires<br />';
echo $oilqty. ' bottles of oil<br />';
echo $sparkqty. ' spark plugs<br />';

$totalqty = 0;
$totalqty = $tireqty + $oilqty + $spakqty;
echo 'Items ordered: ' .$totalqty.'<br />;

$totalamount = 0.00;

define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);

$totalamount = $tireqty * TIREPRICE
    + $oilqty * OILPRICE
    + $sparkqty * SPARKPRICE;
   
echo 'Subtotal: $'.number_format($totalamount,2).'<br />;

$taxrate = 0.10; // local tax is 10%
$totalamount = $totalamount * (1 + $taxrate);

echo 'Total including tax: $'.number_format(stotalamount,2).'<br />

?>

Line 27 is define['TIREPRICE', 100); The book seems to be using PHP5 and mySQL5 is the "define" something that is new to PHP5?

Thanks
Nils
Go to the top of the page
 
+Quote Post
ChronicLoser
post Jan 14 2005, 02:34 AM
Post #2


Premium Member
Group Icon

Group: Members
Posts: 240
Joined: 13-November 04
From: Arizona
Member No.: 1,356



whenever it says
QUOTE
expecting ',' or ';' in /home/nilsc/public_html/bobs/processorder.php

it means that you simply forgot a semicolon. And after a quick runthrough, i found that you forgot a semicolon here:
CODE

echo 'Total including tax: $'.number_format(stotalamount,2).'<br />

so add a (;) and you're done ^_^
Go to the top of the page
 
+Quote Post
NilsC
post Jan 14 2005, 02:00 PM
Post #3


To Err Is Human, To Forgive Divine
Group Icon

Group: Members
Posts: 558
Joined: 24-December 04
From: http://www.ultimatekayakfishing.com/
Member No.: 1,871



I changed the ' in the define statement to ". I think I was defining an array instead of a constant.
Now the error moved down to the echo 'Subtotal: $' line and I tried 2 different ways of formatting the $totalamount and I still get the same error different line:

CODE
define("TIREPRICE", 100);
define("OILPRICE", 10);
define("SPARKPRICE", 4);

$totalamount = $tireqty * TIREPRICE
    + $oilqty * OILPRICE
    + $sparkqty * SPARKPRICE;
   
echo 'Subtotal: $' .number_format($totalamount, 2, '.', ',').'<br />;

$taxrate = 0.10; // local tax is 10%
$totalamount = $totalamount * (1 + $taxrate);

echo 'Total including tax: $' .number_format($totalamount, 2).'<br />;


What am I overlooking here. I know I can pop the disk in that came with the book to get the code ready made but that will not teach me how to find errors in the code. I think I learn more by hacking it until I figure it out or....

Thanks for any pointers
Nils
Go to the top of the page
 
+Quote Post
NilsC
post Jan 14 2005, 11:20 PM
Post #4


To Err Is Human, To Forgive Divine
Group Icon

Group: Members
Posts: 558
Joined: 24-December 04
From: http://www.ultimatekayakfishing.com/
Member No.: 1,871



I found my error so anyone else who encounters the same problem... cross your t's and dot your i's smile.gif

I had forgotten a ' after the <br />
CODE
echo 'Items ordered: $'.$totalqty.'<br />';

$totalamount = 0.00;

define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);

$totalamount = $tireqty * TIREPRICE
    + $oilqty * OILPRICE
    + $sparkqty * SPARKPRICE;
   
echo 'Subtotal: $'.$totalamount.'<br />';

$taxrate = 0.10; // local tax is 10%
$totalamount = $totalamount * (1 + $taxrate);

echo 'Total including tax: $'.number_format($totalamount,2).'<br />';

Here is the updated code that worked.

Nils
Go to the top of the page
 
+Quote Post
ChronicLoser
post Jan 15 2005, 12:07 AM
Post #5


Premium Member
Group Icon

Group: Members
Posts: 240
Joined: 13-November 04
From: Arizona
Member No.: 1,356



lol, sorry i didn't catch that for ya. I just saw a missing semicolon and decided that it was the problem so i didn't look through the rest =P glad you fixed it up though ^_^
Go to the top of the page
 
+Quote Post
NilsC
post Jan 15 2005, 12:16 AM
Post #6


To Err Is Human, To Forgive Divine
Group Icon

Group: Members
Posts: 558
Joined: 24-December 04
From: http://www.ultimatekayakfishing.com/
Member No.: 1,871



I guess I have to be less sloppy while working on this. The biggest problem for me are missing the semicolons and use a capital S instead of $ wink.gif

It's killing me... but in order for me to learn I have to do the hack job... copying from the disc don't help me any.

I'm learning!
Nils
Go to the top of the page
 
+Quote Post
mastercomputers
post Jan 15 2005, 12:08 PM
Post #7


PESTICIDAL MANIAC
Group Icon

Group: Members
Posts: 626
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27



Hey,

define is not new at all, this is how you can create constants in PHP, variables that can not be altered by your code.

Say you defined MAX_FILE_SIZE:

<?php
if(!defined('MAX_FILE_SIZE')) // checks whether we've already set MAX_FILE_SIZE
    [/tab]define('MAX_FILE_SIZE', 8192); // sets MAX_FILE_SIZE to 8192

if(constant('MAX_FILE_SIZE')) // checks whether MAX_FILE_SIZE is a constant
[tab]echo constant('MAX_FILE_SIZE'); // prints the constant MAX_FILE_SIZE

if(defined('MAX_FILE_SIZE')) // checks whether MAX_FILE_SIZE is set
    MAX_FILE_SIZE++; // add 1 to MAX_FILE_SIZE (cannot do, error on this line)
?>

Since I try altering MAX_FILE_SIZE by increasing it by 1, I would get a parse error on this line. You will encounter parse errors quite a lot and usually the message will help you find the problem, missing semi-colons or commas, etc. Although this message doesn't really help understand the problem, you should have a style that constants are all in capital letters, you may also like to prefix it with an underscore _ so it won't conflict with reserved keywords, not likely PHP but C/C++ you would.


Cheers,


MC
Go to the top of the page
 
+Quote Post
matty_023
post Jan 31 2005, 05:04 AM
Post #8


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 2
Joined: 31-January 05
Member No.: 2,438



I find a good way to prevent missing apostrophes and other such things is to do sets together. When you implement your first ‘ implement your second straight away ‘’ then add the text inside ‘hello world’. As in SGML I build inwards. Doing so is just simple and prevents so many simple errors popping up later, though watch that insert button write over all your work lol.

1) <name></name>
2) <name>Matthew</name>
Go to the top of the page
 
+Quote Post
mastercomputers
post Jan 31 2005, 05:28 AM
Post #9


PESTICIDAL MANIAC
Group Icon

Group: Members
Posts: 626
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27



The text editor you use can also help you prevent such problems with syntax hilighting, colour coding, etc.

This will allow you to pick up the problems more easily. I use UltraEdit under Windows, but you'll find there's quite a lot of others out there. On Linux anjuta for C/C++, Perl, etc, can be configured for any other languages too, but sometimes it's easier just using the provided text editor like kwrite. Again it's really personal preference in what you choose. I usually do most things in console anyways.


Cheers,

MC
Go to the top of the page
 
+Quote Post
NilsC
post Jan 31 2005, 01:50 PM
Post #10


To Err Is Human, To Forgive Divine
Group Icon

Group: Members
Posts: 558
Joined: 24-December 04
From: http://www.ultimatekayakfishing.com/
Member No.: 1,871



I'm using first page 2000 for my php and html edits and EditPad Lite for the css code. Is there a css editor out there (that high lights syntax?)

1'st page 2000 works good for me and my needs right now. Does UltraEdit highlight the syntax on css sheets? or is that not possible.

Working inwards, I'm doing that but not on a regular bases yet. I'm still memorizing the syntaxes and learning the basics. When I can write one simple page without going into the book looking at the syntax, then I'll graduate myself to the next level smile.gif

I'm using 3 books to get the basics down, and web resources on w3schools and sitepoint and a few others. One of the books are CSS only, the second and third is php & mySQL (Introductory and intermediate).

The basic template for the site is 80% done so I'm working on the css, html and php right now. Then when that is done I'll build the mySQL db for the dynamic data that is going onto the pages and the forms to use for populating the tables.

Nils
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. PHP paFileDB error(2)
  2. Php Problem - Unique Counter(4)
  3. A Php Gallery Commenting Script Question...(2)
  4. Mail() Not Working(4)
  5. In Php, How To Not Display Mysql Connection Error?(4)
  6. Php Wget(3)
  7. Coding A Private Message System(4)
  8. E-mail List Error(4)
  9. Got A Wee Error - Can You Help?(13)
  10. Installed A PR Checker Script - But Not Working Correctly(6)
  11. Error On Submit Page(10)
  12. Unexpected Error(2)
  13. Php Math Error(4)
  14. Warning: Mysql_num_rows()(1)
  15. How To Make A PM (Personal Message) System?(5)
  1. Php Error-where To Put "?>"(2)
  2. Can't Make This Query Working.(2)
  3. Cant Find The Error(2)
  4. Php Configuration Error?(6)


 



- Lo-Fi Version Time is now: 22nd November 2008 - 04:03 PM