Adding a New Record to the Database in PHP

Let's now create a page new.php for adding a new user to our database. Let's create a form for this:

new.php<form action="" method="POST">
  <input name="name">
  <input name="age">
  <input name="salary">
  <input type="submit">
</form>

After submitting the form, we will save its data to the database. First, let's catch the moment of form submission itself:

new.php<?php
  if (!empty($_POST)) {
    // here will be the form processing code
  }
?>

Inside the condition, let's get our data into variables:

new.php<?php
  $name = $_POST['name'];
  $age = $_POST['age'];
  $salary = $_POST['salary'];
?>

Let's form an INSERT query for the data:

new.php<?php
  $query = "INSERT INTO users SET name='$name', age='$age', salary='$salary'";
?>

Let's execute this query:

new.php<?php
  mysqli_query($link, $query) or die(mysqli_error($link));
?>
Задание 1

On the page new.php implement a form for adding a new user.

Задание 2

Modify the previous task so that after submitting the form, the values from it are not cleared.