<html> <head> <title>Formtest</title> </head> <body> <form name="cucak" method="post" action="action.php"> Name:<br> <input name="name" type="text" size="25"><br> Surname:<br> <input name="surname" type="text" size="25"><br> Email:<br> <input name="email" type="text" size="25"><br> <input type="submit" value="Ok"> </form> </body> </html> 

Help write the program action.php, and make sure that the entered data is added to the table

  • Give at least the structure of the table or something. And what have tried to do. - Sh4dow
  • Yes, he did not try anything. Even go to the site translit.ru. =) - knes
  • table name = "cucak", hello countryman) - nikotm

3 answers 3

so that the table can be added to the infinite and at the same time “not lost”, you need to use either the session or the cookie or the data storage.
those. for example, 1 value has already been added to the table, we already have, for example, $ _SESSION ['table'] [0], then we do something like this in the drawing itself

 <table> <tr> <td>Name</td> <td>Email</td> </tr> <?foreach($_SESSION['table'] as $row):?> <tr> <td><?$row['name']?></td> <td><?$row['email']?></td> </tr> <?endforeach;?> </table> 

PS: I did not write the finished code (see the post time: D), but I think the idea is clear.


<form target="_blank"> in a new tab, but in order in a new window without JS dancing with a tambourine by the fire can not do :)

  • I play this role hidden field. - knes
  • but IMHO is better all the way in the cookies or in the session :) - Zowie
  • Better in the database. =. = But these are little things - knes
  • But how can you make the result open in a new window ?? - muerto
  • thanks, it’s already done, only the data in the table has remained, and the list is muerto
 <?php $table = array(); if(isset($_POST['table'])){ $table64 = base64_decode($_POST['table']); $table = unserialize($table64); } $vars = array('name','surname','email'); $row = array(); foreach($vars as $var){ if(!empty($_POST[$var])){ $row[$var] = $_POST[$var]; }else{ $row[$var] = 'N/A'; } } if($row['name']!='N/A' || $row['surname']!='N/A' || $row['email']!='N/A'){ $table[] = $row; } $table64 = serialize($table); $table64 = base64_encode($table64); ?> <html> <head> <title>Formtest</title> </head> <body> <form name="cucak" method="post" action="action.php"> Name:<br> <input name="name" type="text" size="25"><br> Surname:<br> <input name="surname" type="text" size="25"><br> Email:<br> <input name="email" type="text" size="25"><br> <input type="submit" value="Ok"> <input type="hidden" name='table' value="<?=$table64?>" /> </form> </body> <?php if(isset($table)){?> <table> <tr><td>Name</td><td>Surname</td><td>Email</td></tr> <?php foreach($table as $row){ printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>",$row['name'],$row['surname'],$row['email']); } ?> </table> <?php } ?> </html> 
  • Thanks, but when I finish the second three, the first one is deleted and the second is written instead - muerto
  • It works for me. The script works while you fill in triples and click OK. When you refresh the page, everything will disappear: the data is stored in a hidden-field. Which browser? - knes
  • Opera 11, it works for me, but it does not add to the top three under the first one, but instead adds it to the muerto

In a new window

 <form name="cucak" action="action.php" method="post" target="foo" onsubmit="window.open('', 'foo', '')">