title: How to find out if rows exist in database when inserting multiple rows by one submit
body: <p>A newbie is asking help here. I’ve created a multiple inserting form, where’s 3 fields. Let’s say that fields’ name are: “name”, “surname” and “age”. I’m trying to insert them into database in the case if there’s not already same data in database. How can I check if there’s already exist data there?</p>
  
  <p>When I'm trying to insert just one record to database it's quite easy job to check if the same record is saved already in the database or not. The problem appears when I'll try to insert multiple records to the same database. In multiple record case I've to use foreach loop to succeed, but I don't know how to do that. 
  Thanks in advance for any help.</p>
  
  <pre><code>&lt;?php
  
  include('../mysqli_connect3.php');
  include 'includes/header.html';
  $page = 'quest_insert.php';
  
  for($i = 0; $i &lt; $_POST['numbers']; $i++) {
      if (!empty($_POST["name"][$i]) &amp;&amp; !empty($_POST["surname"][$i]) &amp;&amp; !empty($_POST["age"][$i])) {
          $sql = mysqli_query($dbc, "SELECT name, surname, age FROM users WHERE 'name' = '".$_POST['name'][$i]."' AND 'surname' = '".$_POST['surname'][$i]."' AND 'age' = '".$_POST['age'][$i]."'");
          if (mysqli_num_rows($sql) &gt; 0) {
          echo "Data '" . $name[$i] . "' and '" . $surname[$i] ."' are already saved in database!";
          mysqli_close($dbc);
          header("refresh:5; url=$page");
  
          } else {
          $name[$i] = mysqli_escape_string($dbc, $_POST["name"][$i]);
          $surname[$i] = mysqli_escape_string($dbc, $_POST["surname"][$i]);
          $age[$i] = ($_POST["age"][$i]);
          mysqli_query($dbc, "INSERT INTO users (name, surname, age) VALUES ('".$_POST['name'][$i]."', '".$_POST['surname'][$i]."','".$_POST['age'][$i]."')");
          echo "Data '" . $name[$i] . "' and '" . $surname[$i] ."' are inserted into database! &lt;br /&gt;";
          header("refresh:6; url=$page");
      }} else {
          echo "You forgot to fill in all fields!";
          header("refresh:2; url=$page");
          exit();
      }
      }
  
  ?&gt;
  </code></pre>