Jump to content
Larry Ullman's Book Forums

Issue With Comparative Operators

Recommended Posts

Hi, I've got a issue with Comparative Operators in the Calendar.php exercise. It's not a problem, because the script works - but only when I make a slight alteration to the original script (which I've cut and pasted from the online edition of the book)


When I run the script as is:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />




<form action="calendar.php" method="post">

<?php # Script 2.6 - calendar.php

$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

echo '<select name="month">';

foreach ($months as $key => $value) {

echo "<option value=\"$key\">$value</option>\n";


echo '</select>';

echo '<select name="day">';

for ($day = 1; $day <= 31; $day+ +) {

echo "<option value=\"$day\">$day</option>\n";


echo '</select>';

echo '<select name="year">';

for ($year = 2011; $year <= 2021; $year+ +) {

echo "<option value=\"$year\">$year</option>\n";


echo '</select>';






I receive the following error message:


Parse error: syntax error, unexpected ')' in C:\xampp\htdocs\phpexamples\calendar.php on line 17


But when I make a simple change


for ($day = 1; $day <= 31; $day+ +) { to for ($day = 1; $day <= 31; $day++) {


the script runs correctly until it finds a similar error for $year a few lines farther down. When I put those two plus signs together, bingo, the script returns the pull down calendar as it should.


As you can well imagine, this sort of behavior is very unsettling for a newbie like me. Aren't spaces like this supposed to be irrelevant? Shouldn't both variants of the script work?


Anyway, I'm hoping that you settle my nerves with an explanation of this phenomenon.


As to my system, I'm using Notepad++ as a text editor and running a personal server on my pc. When I run the predefined.php script, I get the following output about my environment:


You are running the file:


You are viewing this page using:

Mozilla/5.0 (Windows NT 6.0; rv:8.0) Gecko/20100101 Firefox/8.0

This server is running:

Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1.


Regards and thanks in advance!

Link to comment
Share on other sites

Could you please provide a specific script in the downloaded scripts (and provide the URL used to download the script) where you believe there is + + with a space? Because the code made available is the code I personally used when writing the book, and it simply would not work with a space there, as you've discovered.

Link to comment
Share on other sites


  • Create New...