title: Adding multiple entries to a table
body: <p>I am trying to register customers for a continuing education web site I am creating and need to add multiple entries to the phpMyAdmin table &quot;users&quot; for registration purposes. I am trying to add multiple entries, 25 total.</p>
  <p>As you will see, I have tried the <code>mysqli_multi_query()</code> function to add them all but I cannot create a new record of those entries.</p>
  <p>It shows that I am connected to the database and I have checked all values in the code with those in the table and they are ordered. So my questions are:</p>
  <ul>
  <li>Is there a limit of entries per table?</li>
  <li>Is it best to add few entries at a time than a sign-in page with multiple lines?</li>
  <li>Am I trying to do too much in one file and need to split my job?</li>
  </ul>
  <p>Error I am getting:</p>
  <pre><code>You are connected to the database. Error: INSERT INTO users (myName, home1, home2) VALUES (?, ?, ?);INSERT INTO users (city, ste, zip) VALUES (?, ?, ?);INSERT INTO users (email, certification, experience) VALUES (?, ?, ?);INSERT INTO users (employer, marketing, gender) VALUES (?, ?, ?);INSERT INTO users (dob, recert, full_name) VALUES (?, ?, ?);INSERT INTO users (phone, bHome1, bHome2) VALUES (?, ?, ?);INSERT INTO users (bCity, bState, bZip) VALUES (?, ?, ?);INSERT INTO users (payment, cardNum, expDate) VALUES (?, ?, ?);INSERT INTO users (pwd) VALUES (?);
  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?, ?, ?);INSERT INTO users (city, ste, zip) VALUES (?, ?, ?);INSERT INTO users (' at line 1
  </code></pre>
  <p>The code so far validates all entries, checks if there are blank entries, and uses the function test-input. Any help is appreciated, including sources from where to learn PHP that worked better for your education. Thanks in advance and thank you for listening.</p>
  <pre><code>&lt;?php
  // Defined variables for validation
  $myNameErr = $home1Err = $home2Err =$cityErr = $steErr = $zipErr = $emailErr = &quot;&quot;;
  $certificationErr = $experienceErr = $employerErr = $marketingErr = &quot;&quot;;
  $genderErr = $dobErr = $recertErr = $full_nameErr = $phoneErr = $bHome1Err = &quot;&quot;; 
  $bHome2Err = $bCityErr = $bStateErr = $bZipErr = $paymentErr = $cardNumErr = &quot;&quot;;
  $expDateErr = $pwdErr = $pwd2Err = &quot;&quot;;
  $myName = $home1 = $home2 = $city = $ste = $zip = $email = &quot;&quot;;
  $certification = $experience = $employer = $marketing = &quot;&quot;;
  $gender = $dob = $recert = $full_name = $phone = $bHome1 = &quot;&quot;; 
  $bHome2 = $bCity = $bState = $bZip = $payment = $cardNum = &quot;&quot;;
  $expDate = $pwd = $pwd2 = &quot;&quot;;
  
  // Validating fields by checking if fields are empty
  if ($_SERVER[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;) {
      // Checks full name
      if (empty($_POST['myName'])) {
          $myNameErr = &quot;Name required.&quot;;
      } else {
          $myName = test_input($_POST['myName']);
          // check if name only contains letters and whitespace
          if (!preg_match(&quot;/^[a-zA-Z-' -.]*$/&quot;, $myName)) {
              $myNameErr = &quot;Only letters and white space allowed&quot;;
          }
      }
      // Checks address
      if (empty($_POST['home1'])) {
          $home1Err = &quot;Address required.&quot;;
      } else {
          $home1 = test_input($_POST['home1']);
      }
      // Checks additional address input
      if (empty($_POST['home2'])) {
          $home2 = test_input($_POST['home2']);
      }
      // Checks for city
      if (empty($_POST['city'])) {
          $cityErr = &quot;City is required.&quot;;
      } else {
          $city = test_input($_POST['city']);
      }
      // Checks for state
      if (empty($_POST['ste'])) {
          $steErr = &quot;State is required.&quot;;
      } else {
          $ste = test_input($_POST['ste']);
      }
      // Checks for zipcode
      if (empty($_POST['zip'])) {
          $zipErr = &quot;Zip code is required.&quot;;
      } else {
          $zip = test_input($_POST['zip']);
      }
      // Checks for email and if format is correct
      if (empty($_POST['email'])) {
          $emailErr = &quot;Email is required.&quot;;
      } else {
          $email = test_input($_POST['email']);
          // check if e-mail address is well-formed
          if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
              $emailErr = &quot;Invalid email format&quot;;
          }
      }
      // Confirms the current email
      if (empty($_POST['email2'])) {
          $email2Err = &quot;Confirm your email.&quot;;
      } else {
          $email2 = test_input($_POST['email2']);
          // check if e-mail address is well-formed
          if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
              $email2Err = &quot;Invalid email format&quot;;
          }
          // Check if emails match
          if ($email != $email2) {
              $email2Err = &quot;Emails don't match!&quot;;
          }
      }
      // Checks for modality certification
      if (empty($_POST['certification'])) {
          $certificationErr = &quot;Current certification is required.&quot;;
      } else {
          $certification = test_input($_POST['certification']);
      }
      // Checks for years of experience
      if (empty($_POST['experience'])) {
          $experienceErr = &quot;Years of experience are required.&quot;;
      } else {
          $experience = test_input($_POST['experience']);
      }
      // Checks for the current employer
      if (empty($_POST['employer'])) {
          $employerErr = &quot;Current employer required.&quot;;
      } else {
          $employer = test_input($_POST['employer']);
      }
      // Input about how they heard about us
      if (empty($_POST['marketing'])) {
          $marketing = &quot;&quot;;
      } else {
          $marketing = test_input($_POST['marketing']);
      }
      // Checks for gender
      if (empty($_POST['gender'])) {
          $genderErr = &quot;Gender required.&quot;;
      } else {
          $gender = test_input($_POST['gender']);
      }
      // Check the date of birth
      if (empty($_POST['dob'])) {
          $dobErr = &quot;Date of birth required.&quot;;
      } else {
          $dob = test_input($_POST['dob']);
      }
      // Checks their end of certification date
      if (empty($_POST['recert'])) {
          $recertErr = &quot;Recertification date required.&quot;;
      } else {
          $recert = test_input($_POST['recert']);
      }
      // Checks name as in credit card
      if (empty($_POST['full_name'])) {
          $full_nameErr = &quot;Name as written in credit card required.&quot;;
      } else {
          $full_name = test_input($_POST['full_name']);
      }
      // Checks for phone number
      if (empty($_POST['phone'])) {
          $phoneErr = &quot;Phone number is required.&quot;;
      } else {
          $phone = test_input($_POST['phone']);
      }
      // Billing Information
      // Checks for billing address
      if (empty($_POST['bHome1'])) {
          $bHome1 = &quot;&quot;;
      } else {
          $bHome1 = test_input($_POST['bHome1']);
      }
      // Checks for billing address 2
      if (empty($_POST['bHome2'])) {
          $bHome2 = &quot;&quot;;
      } else {
          $bHome2 = test_input($_POST['bHome2']);
      }
      // Checks for billing city
      if (empty($_POST['bCity'])) {
          $bCity = &quot;&quot;;
      } else {
          $bCity = test_input($_POST['bCity']);
      }
      // Checks for billing state
      if (empty($_POST['bState'])) {
          $bState = &quot;&quot;;
      } else {
          $bState = test_input($_POST['bState']);
      }
      // Checks for billing zip code
      if (empty($_POST['bZip'])) {
          $bZip = &quot;&quot;;
      } else {
          $bZip = test_input($_POST['bZip']);
      }
      // Checks for payment mode
      if (empty($_POST['payment'])) {
          $paymentErr = &quot;Mode of payment is required.&quot;;
      } else {
          $payment = test_input($_POST['payment']);
      }
      // Checks for credit card number
      if (empty($_POST['cardNum'])) {
          $cardNumErr = &quot;Credit card number required.&quot;;
      } else {
          $cardNum = test_input($_POST['cardNum']);
      }
      // Checks for expiration date
      if (empty($_POST['expDate'])) {
          $expDateErr = &quot;Card's expiration date required.&quot;;
      } else {
          $expDate = test_input($_POST['expDate']);
      }
      // Checks for password
      if (empty($_POST['pwd'])) {
          $pwdErr = &quot;Password required.&quot;;
      } else {
          $pwd = test_input($_POST['pwd']);
      }
      // Asks to confirm password and if both match
      if (empty($_POST['pwd2'])) {
          $pwd2Err = &quot;Confirm your email.&quot;;
      } else {
          $pwd2 = test_input($_POST['pwd2']);
          // Check if passwords match
          if ($pwd != $pwd2) {
              $pwd2Err = &quot;Passwords don't match!&quot;;
          }
      }
  }
  
  function test_input($data) {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      return $data;
  } 
  
  if(isset($_POST['submit'])){
      $myName = $_POST['myName'];
      $home1 = $_POST['home1'];
      $home2 = $_POST['home2'];
      $city = $_POST['city'];
      $ste = $_POST['ste'];
      $zip = $_POST['zip'];
      $email = $_POST['email'];
      $certification = $_POST['certification'];
      $experience = $_POST['experience'];
      $employer = $_POST['employer'];
      $marketing = $_POST['marketing'];
      $gender = $_POST['gender'];
      $dob = $_POST['dob'];
      $recert = $_POST['recert'];
      $full_name = $_POST['full_name'];
      $phone = $_POST['phone'];
      $bHome1 = $_POST['bHome1'];
      $bHome2 = $_POST['bHome2'];
      $bCity = $_POST['bCity'];
      $bState = $_POST['bState'];
      $bZip = $_POST['bZip'];
      $payment = $_POST['payment'];
      $cardNum = $_POST['cardNum'];
      $expDate = $_POST['expDate'];
      $pwd = $_POST['pwd'];
  
      // Adding multiple values to database table users
      $sql = &quot;INSERT INTO TABLE users (myName, home1, home2) VALUES (?, ?, ?);&quot;;
      $sql .= &quot;INSERT INTO TABLE users (city, ste, zip) VALUES (?, ?, ?);&quot;;
      $sql .= &quot;INSERT INTO TABLE users (email, certification, experience) VALUES (?, ?, ?);&quot;;
      $sql .= &quot;INSERT INTO TABLE users (employer, marketing, gender) VALUES (?, ?, ?);&quot;;
      $sql .= &quot;INSERT INTO TABLE users (dob, recert, full_name) VALUES (?, ?, ?);&quot;;
      $sql .= &quot;INSERT INTO TABLE users (phone, bHome1, bHome2) VALUES (?, ?, ?);&quot;;
      $sql .= &quot;INSERT INTO TABLE users (bCity, bState, bZip) VALUES (?, ?, ?);&quot;;
      $sql .= &quot;INSERT INTO TABLE users (payment, cardNum, expDate) VALUES (?, ?, ?);&quot;;
      $sql .= &quot;INSERT INTO TABLE users (pwd) VALUES (?);&quot;;
  
      // Trying to save to the database
      if (mysqli_multi_query($con, $sql)) {
          echo &quot;New records created successfully&quot;;
      } else {
          echo &quot;Error: &quot; . $sql . &quot;&lt;br&gt;&quot; . mysqli_error($con);
      }
  
  
      $hashPwd = password_hash($pwd, PASSWORD_DEFAULT);
  
      $stmt-&gt;bind_param(&quot;sssssssssssssssssssssssss&quot;, $myName, $home1, $home2, $city, $ste, $zip, 
          $email, $certification, $experience, $employer, $marketing, $gender, $dob, $recert, 
          $full_name, $phone, $bHome1, $bHome2, $bCity, $bState, $bZip, $payment, $cardNum,
          $expDate, $hashPwd); 
        
      mysqli_close($con);
  }
  </code></pre>