CMS template issue

I hope that bleeding over from the PHP Live course forum is appropriate in this instance. I am reworking the CMS building component of the course with emphasis on understanding and clarity rather than the monkey see monkey do approach is took initially. I writing the code for the authors.html.php template I continue to get an unspecified pares error when running the template on local host server. I have the code identical as given in the example in the Day 12 course files and article.

<?php include_once $_SERVER['DOCUMENT_ROOT'].
	'/includes/helplers.inc.php'; ?>
<!DOCTYPE html >
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mange Authors</title>
</head>
	<body>	
	<h1>Manage Authors</h1>
	<p><a href="?add">Add new author</a></p>
	<ul>
		<?php  foreach ($ authors  as  $ author); ?>
			<li>
				<form action="" method="post">
				<div>
					<?php htmlout(author['name']);?>
					<input type="hidden" name="id" value=" 
					<?php echo $author ['id']; ?>">
					<input type="submit" name="action" value="edit">
				<input type="submit" name="action" value="delete">
					</div>
				</form>
			</li>
		
		<?php end foreach; ?>
	</ul>
	<p><a href=". . ">Return to JMS Home</a></p>

</body>

</html

Error reads “Parse error: parse error, expecting T_VARIABLE' or ‘$’’ in C:\wamp\www\admin\authors\authors.html.php on line 13”

In doing some reading @ W3schools It says that “foreach” is a loop and it does not seem to be applied as such in this script.

Any thoughts appreciated,
MIKE E:eye::eye:

You want:

<?php  foreach ($authors as $author): ?>

Not:

<?php  foreach ($authors['id'] as  $author['id']): ?>

The second one doesn’t make any sense.

Kevin,
Thanks for your reply you were correct in what I was doing. However just one more inquiry I open the CMS at this pointg with this url
http://localhost/admin/authors/index.php

I get these error messages
Notice: Undefined index: id in C:\wamp\www\admin\authors\authors.html.php on line 13

Warning: Invalid argument supplied for foreach() in C:\wamp\www\admin\authors\authors.html.php on line 13

I may just start all over again. Unless you see something. I am afraid that at this point you would have to see all the files in the project to find my issue.

Regards and thanks,
MIKE E:eye::eye:

BTW I finished Russ’s CSS class and I am signed up for the HTML 5 & CSS 3 classes as well. Thanks to Site Point I have had a banner web design developer education year so far I have taken every class offered. You folks are developing a awesome concept in this kind of training.

Hey ebermed,

<?php  foreach ($authors  as  $author): ?>

This is the correct way to write the foreach loop. After that, if you get a “Undefined variable $authors” error, I would say you are probably making the mistake of loading the template directly by requesting it with your browser, rather than pointing your browser at the index.php controller script, which creates the $authors variable and then includes the authors.html.php template that uses it.

My guess

$author [‘id’]

Because that should be

$author[‘id’]

No space. Be careful about putting spaces where they don’t belong. It’s a program not an English paper :slight_smile:

I am really stuck here I am getting an undeclared variable error message when I try to open the template via local host. Line 13 is the opening statement of the foreach loop. and I cannot see any other way of writing it . Questions I ask myself as I try to figure it out are
1 what purpose does the foreach loop serve in this instance?

2 Why is the foreach statement inserted in this unique position in the script?

3 Where was the $author, $authors variables declared in the first place. Wait in PHP you declare as you go right?

4 If it is true that one of the 2 variables in the foreach loop opening statement are undeclared, what makes that condition true.

That is where my head is at. Any ideas that will get me moving in the right directions?

Thanks,
MIKE E:eye::eye:

Thanks for your help with this. I may have place the subid incorrectly but I came out the these results. I am including the code as it is now.

<?php foreach ($authors['id']  as $author['id']) :  ?>
			<li>

With Results:

Thanks for you patience,
MIKE E:eye::eye:

Whatever sets $author is outside the scope of the code you provided. Sorry.

Your very informative link clearly explained the issue with the foreaach syntax. which explained the “:” vs “;” question. Thanks.I had a few other parse errors but I was able to locate and correct them one of course was the obligatory you can’t spell error:eek::nono:

Man I REALLY love this stuff seriously nothing like it to keep the old squash firing on all synapses!

I’m sure our paths will cross again so until then THANKS,
MIKE E:eye::eye:

Review this more closely

http://us.php.net/manual/en/control-structures.alternative-syntax.php

Your answer below if you’re still stumped after reading that…

There are three errors in your code, not one. First a control structure in braceless syntax ends with a colon, not a semicolon. Also, the $ is to be attached directly to the variable name – $var – not – $ var.

Hence it’s

<?php  foreach ($authors  as  $author): ?>

The second error is the endforeach statement is all one word, not “end foreach”

<?php endforeach; ?>

Incidently, the semicolon is not necessary right before a script close ( the ?> mark ). So <? endforeach ?> works just as well.