Hello Everyone,

I'm trying to change the page content based on which link is pressed. Can someone tell em hwy my code doesn't work, please? Last error I got was a parse error on line 43. Thanks

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP content Change </title>
<style type="text/css">
li {
	list-style-type: none;
	display: inline;
	margin-right: 15px;
}
</style>
</head>

<body>
<img src="" width="980" height="114" />
<h1>ABOUT US</h1>
<ul>
  <li><a href="contentchange.php?link=1">President</a></li>
  <li><a href="contentchange.php?link=2">Staff</a></li>
  <li><a href="contentchange.php?link=3">Board of Directors</a></li>
</ul>
<?php
if (isset($_REQUEST['link'])) {
$link = $_REQUEST['link'];} 
else {$link = 1;}
  switch ($link) {
  case 1:
  include ("aboutroots.html");
  break;
  case 2:
  include ("rootsstaff.html");
  break;
  case 3:
  include ("rootsdirectors.html");
  break;
  default:
  	$link = 1;
	break;
 ?>
</body>
</html>

Dani AI

Generated

As pointed out, the symptom (a parse error reported near the end of the file) is consistent with a missing closing brace: the switch block is never closed before the PHP end tag. As noted, PHP often reports the error at or after the final line when an earlier block wasn't closed. Adding the missing closing brace to terminate the switch before ?> will clear the immediate parse error.

A few practical improvements and hardening steps not shown in the thread:

  • Prefer $_GET (or filter_input) instead of $_REQUEST for URL parameters and validate/cast the value to an integer.
  • Use a whitelist array that maps permitted integers to filenames so includes cannot be manipulated by user input.
  • Check is_readable() before including; use include_once/require_once as appropriate.
  • Put a meaningful action in the default case (e.g., include the fallback page) rather than only resetting the variable.
  • For debugging, run php -l to lint the file and enable error_reporting(E_ALL)/display_errors on a local dev box; check server error logs on production. Consistent indentation and an editor with brace matching also make missing braces obvious.

A compact, safer pattern (illustrative):

<?php
$link = filter_input(INPUT_GET, 'link', FILTER_VALIDATE_INT, ['options'=>['default'=>1,'min_range'=>1]]);
$pages = [1=>'page_about.html', 2=>'page_staff.html', 3=>'page_board.html'];
$file = $pages[$link] ?? $pages[1];
if (is_readable($file)) { include $file; } else { include $pages[1]; }
?>

These steps both fix the immediate parse error and reduce future syntax/security issues.

Recommended Answers

All 3 Replies

Member Avatar for Member #733618

The error is that you forgot a } after line 40 !

please specify in which line there is an error accoding to your code....as line 43 is last line...

Member Avatar for Member #733618

please specify in which line there is an error accoding to your code....as line 43 is last line...

Look at line 40... he forgot a "}"...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.