PHP Harvard Generator Form Help

Hi

For school we need to make a Bibliography generator for a book with multiple authors. The teacher want us to have a text field where someone can enter the amount of authors they need to. I’ve got the code for the actual generator, i’m just stuck on the part where we need to make another form to enter the amount of author fields that will be displayed. I’ve just started PHP so this could be very simple to others :P.

this is my generator code:

[php]<?php

if(isset($_POST [‘go’])){

@$times =$_POST[‘times’];
@$author =$_POST[‘authorsurname’];
@$author2 =$_POST[‘authorsurname2’];
@$author3 =$_POST[‘authorsurname3’];
@$book =$_POST[‘booktitle’];
@$placepublished =$_POST[‘placepublished’];
@$yearpublished =$_POST[‘yearpublished’];
@$publisher =$_POST[‘publisher’];
@$edition =$_POST[‘edition’];
@$pages =$_POST[‘pages’];

for ($author=1; $author<=$times; $author++)
{
echo ’
Author 1:
';
}

echo ’ Title of Book:



Place Published:



Year Published:



Publisher:



Edition:



Pages Used:





';
if(!$author || !$book || !$placepublished || !$yearpublished || !$publisher || !$edition || !$pages)

	{
		echo "Go back and fill out all fields.";
	}
		else
	{
		echo "<b> Your Refernce:</b>";
		echo "<br><br>";
		echo ($author. ". ")." ($yearpublished). ".($book. ". ").($placepublished. ". ").
			 ($publisher. ". ").($pages. ". ");
	}

}
?>[/php]

If someone was able to help me out it would be greatly appreciated. THANKS!

Try this:

[php]
for ($author=1; $author<=$times; $author++)
for ($author=1; $author<=$times; $author++){
echo ’
Author ’ . $author . ':

';
}
echo ‘’;
[/php]

Then to collect the values:

[php]
if (isset($_POST[“Submit”])){
$times = $_POST[“times”];
if ($times == “”) {$times = 1;}
for ($author=1; $author<=$times; $author++){
${‘author’ .$author} = $_POST[‘authorsurname’.$author];
}
}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service