Enter Record to «Protagonist»

See the source of this page for the form html code.

Protagonist :

Nationality :

Id Protagonist Country
3 Bond, James 2
8 Galt, John 3
7 Long, Lazarus 3
4 Maigret, Jules 3
2 Marple, Miss 2
6 Parker Pyne, James 2
1 Poirot, Hercule 1
5 Satterthwaite, Mr 2

Code : (for display purposes, some lines wrap. The ↵ character indicates it. The character is not part of the code)

$path_to_db_script = $_SERVER['DOCUMENT_ROOT']↵
          . "/" . "db/pjjtextbase.php";
require $path_to_db_script;
$protagonist = ptb_connect('protagonist.csv');

if( isset($_POST['submit'])) {
   if ( ( $_POST['protagonist'] <> "" )↵
      && ( $_POST['nationality'] <> "" ) ) {
      $theFile = 'protagonist.csv';
      $max = ptb_max($protagonist,'id')+1;
      $theHero = $_POST['protagonist'];
      $nationality = $_POST['nationality'];
      $fieldValues = "$max|$theHero|$nationality";
      ptb_add( $theFile, 'G', $fieldValues );
   }
}

To display the list to the right of the form, an external PHP file (➠ after_add.php) is included :

<?php
$protagonist = ptb_sort($protagonist, 'protagonist ASC');
$theCount = ptb_count ($protagonist);
$theItem = 0;
?>
<table>
<tr>
  <th>Id</th>
  <th>Protagonist</th>
  <th>Country</th>
</tr>
<?php
for ($i = 0; $i <= $theCount-1; $i++) {
  echo "<tr>
  <td>" . $protagonist[$i]['id'] . "</td>
  <td>" . $protagonist[$i]['protagonist'] . "</td>
  <td>" . $protagonist[$i]['@nationality'] . "</td>
  </tr>";
}
?>
</table>

Feb 17 2021 06:30:58