Basic PHP code problem

Hello there! It’s my first time posting here!

I’m working through a tutorial in the book “PHP and MySQL Web Development” by Luke Welling and Laura Thomson. I’ve got the following code so far for a form and it works the way that it’s supposed to. For some reason, though, my code editor is highlighting a part of it in red and I would like to know why. I’m using the code editor in the webFTP of Dreamhost. It’s highlighting:

[code]'s Auto Parts

Order Results

<?php echo "<p>Order processed at "[/code]

Here is the entire code:

[code]<?php
//create short variable names
$tireqty = $_POST[‘tireqty’];
$oilqty = $_POST[‘oilqty’];
$sparkqty = $_POST[‘sparkqty’];
?>

Bob's Auto Parts - Order Results

Bob's Auto Parts

Order Results

<?php echo "<p>Order processed at ";
  echo date('H:i jS F Y');
  echo "</p>"; 
  echo "<P>Your order is as follows: </p>";
  echo $tireqty.' tires <br>';
  echo $oilqty.' bottles of oil <BR>';
  echo $sparkqty.' spark plugs <BR>';

define(‘TIREPRICE’, 100);
define(‘OILPRICE’, 10);
define(‘SPARKPRICE’, 4);
$totalqty = 0;
$totalamont = 0.00;
?>

[/code]

The form is processing correctly. I just want to know why that portion would be highlighted in red. Do you see anything wrong with it or anything that could be “more correct?” Thanks in advance! (By the way, I had no idea what to call this thread!)

I am also a learning PHP Web Developer, but I may have one idea…

In “Bob’s” you have a " ’ " which ( I am not sure of, but-) arent you suppose to do something like ’ in PHP or something, I dont know, just an idea. But if the code works, I wouldnt worry about it, just the file editor doesnt like what your doing or something.

For both of you…

the first problem is a missing semi-colon at the end of the line. All PHP lines must end with ;

The second issue of the single quote… On HTML you can use it most anywhere as it is just displayed.
inside of strings inside of PHP, it can be used any time if the outside borders are double quotes…

So, this PHP sample:
$myString=" blah blah ’ blah blah"; Is valid…
$myString=" blah blah " blah blah"; NOT valid…
$myString=’ blah blah " blah blah’; Is valid…
$myString=’ blah blah ’ blah blah’; NOT valid…
$myString=" blah blah " blah blah"; Is valid…
$myString=’ blah blah ’ blah blah"; Is valid…

Hope that helps… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service