-1

I am trying to create a repeating form that passes variable and updates the table each time the page is submitted.

for example:

<form action="$_SERVER['PHP_SELF']" method="post">
<p>Student Name: <input type="text" name='studentName[]' size='32'></p>


<button type="submit" name='submit' value='submit'>Submit</button>
</form>


<?php  if(isset($_POST['submit']))
{

$studentName[]=$_POST['studentName']; 

?>
<table border='1'>
<tr><th>Students Name</th></tr>


<?php 
for($x=0; $x < count($studentName); $x++)
{
echo "<tr><td>$studentName[$x]</td></tr>";  
} ?>
</table>


}

   ?>

I know that the above code does not work. What would be the correct way to do something like this? Can someone please write me a correct code that does work. I need to see an example.

I searched all over the internet, but I could not find an example.

Howli
  • 12,291
  • 19
  • 47
  • 72
Daniel Izhar
  • 130
  • 1
  • 12
  • Which part of it doesn't work? The form submission (because you have `$_SERVER['PHP_SELF']` but you're not outputting it via PHP like ``)? Does it not create the rows? Does it look bad? etc... – newfurniturey May 23 '14 at 11:01
  • Why are you using an array for `name` when you have just a single input box? – asprin May 23 '14 at 11:01
  • if you need data to be saved after page submit, you should use some permament data storage. For example database. – Bojan Kovacevic May 23 '14 at 11:05

1 Answers1

0

you have to declare $studentName[] as array befor $studentName = array()

manout
  • 41
  • 2
  • 10