Jump to content

Why this code doesn't run?


Truman
 Share

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
Link to comment
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...

Link to comment
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.

Link to comment
Share on other sites

  • 1 month later...

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...

Link to comment
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. -->
 
Link to comment
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
 Share

×
×
  • Create New...