Jump to content
Truman

Why this code doesn't run?

Recommended Posts

There's a closing quote missing on this line:

print "\t\tfont-size: " . htmlentites($_COOKIES['font_size']) . "; \n 

You can tell because all the following lines are colored green by the syntax highlighter.

You just need to look at the code more carefully.

  • Like 1

Share this post


Link to post
Share on other sites
<!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">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Date Menus</title>
</head>
<body>
<?php // Script 10.1 - menus.php 
function make_date_menus() {
 $months = array(1 => 'January', 'February', 'March', 'Aprile', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
 print '<select name="month">';
  foreach ( $month as $key => $value ) {
   print "\n<option value=\"$key\">$value</option>";
   }
 print '</select>';  
 print '<select name="day">';
  for ($day=0; $day<=31; $day++) {
   print "\n<option value=\"$day\">$day</option>";
  } 
 print '</select>';
 print '<select name="year">
  $start_year = date('Y');
  for ($y = $start_year; $y <= ($start_year + 10); $y++ ) {
   print "\n<option value=\"year\">$y</option>";
   }
 print '</select>';
 } // end of make_date_menus function.
print '<form action="" method="post">';
make_date_menus();
print '</form>';
?>
</body>
</html>

and the error is:

Parse error: syntax error, unexpected 'Y' (T_STRING) in C:\xampp\htdocs\my-site\menus.php on line 23

 

I don't see why 'Y' is an error, I used already existing function...

Share this post


Link to post
Share on other sites

where does closing " ' " of

print '<select name="year">

end? because


$start_year = date('Y');

has taken partially control of ending it!

Edited by dsonesuk
  • Like 1

Share this post


Link to post
Share on other sites

These errors are obvious if you would look at the code coloring.

Share this post


Link to post
Share on other sites

Get a decent php editor that will highlight these errors, before you even begin to view in a browser to rely on php error reporting to inform you of the error.

Share this post


Link to post
Share on other sites

Thank you, now other mistake is reported, but I won't bother you with that. Do you think that online php code checker is good? It usually sends the same message as browser.

Share this post


Link to post
Share on other sites

No! you just need a editor that checks syntax of your code as you type, and highlights the error, usually with warning triangle against the line in question, as said these errors are highlighted before you even get anywhere near looking for them in a browser.

Share this post


Link to post
Share on other sites

Oh, I see. Thank you. Do you think that Sublime Text is good for that purpose? Someone recommended it to me...

Share this post


Link to post
Share on other sites

I wrote a simple code for logout:

<?php // Script 1.7 - logout.php
if (isset($_COOKIE['Samuel'])) {
  setcookie('Samuel', FALSE, time()-300);
}
define('TITLE', 'Logout');
include('templates/header.html');
print '<p>You are now logged out.</p>';
include('templates/footer.html');
?>

but I receive:
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\my-site\all\templates\header.html on line 3

 

This makes no sense to me...

Share this post


Link to post
Share on other sites

The error is on line 3 of the header.html file, you didn't show the code for that.

Share this post


Link to post
Share on other sites

How could I know that the error is on line 3 of another file?

And this is the code for header.html:

<?php // Script 1.4 - header.html 
include('functions.php');
<!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">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" media="all" href="css/style.css" />
<title><?php 
if (defined('TITLE')) {
 print TITLE;
} else {
 print 'My site of quotes.';
}
?></title>
</head>
<body>
 <div id="container">
   <h1>My site of quotes.</h1>
   <br />
   <! -- Begin changeable content. -->
 

Share this post


Link to post
Share on other sites

Simple where error message shows

 

C:\xampp\htdocs\my-site\all\templates\

 

header.html

 

on

 

line 3

 

The error is it has open php tag with php code which also includes html code, which should have escaped with closing php tag.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×