Change associative array value with PHP and FORM HTML

30 Views Asked by At

I have this exercise for school:

  • Write a PHP script that represents a single student's data using an array associative. Each student has a name, age and favorite subject.

  • Provide an "EDIT" link within the output page. The link takes you to a page containing a FORM (html) with three inputs (name, age and favorite subject). Through the form recover the student's information and insert it into the previously created array. Print then the updated array.

My problem is that I don't know how I can update array values from html form. Some advice? Thank you for your help

Script PHP:

  <?php
    $studente = array("nome" => "name", "età" => "age", "materia_preferita" => "subject");
    foreach ($studente as $key => $value) {
        echo $key . " = \n" . $value . "\n" . "<br/>";
    }
    ?>
    </p>
    <p>
    <a href="form.html">Edit</a>
    </p>

Page HTML:

<form method="POST" action="array2.php">
      <input type="text" name="nome[]" placeholder="nome">
      <input type="text" name="età[]" placeholder="età">
      <input type="text" name="materia_preferita[]" placeholder="materia">
      <input type="submit" value="Submit">
</form>
0

There are 0 best solutions below