title: Insert into DB with PHP and Postgresql
body: <p>i don't understand why i can't insert into DB.
  I have create a DB with this table:</p>
  <blockquote>
  <p>prenotazione (id,nome_rich,cognome_rich,email_rich,oggetto_rich)</p>
  <p>interni (id,nome_int,cognome_int,email_int)</p>
  <p>esterni (id,nome_est,cognome_est,email_est)</p>
  </blockquote>
  <p>this is my index.php</p>
  <pre><code>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 
  Transitional//EN&quot; 
  &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
  &lt;html&gt;
  
  &lt;head&gt;
  &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;title&gt;Prenotazione Videoconferenza&lt;/title&gt;
  &lt;script src=&quot;utils.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
  
  Inserire i dati richiesti:&lt;br&gt;&lt;br&gt;
  &lt;form method=&quot;post&quot; action=&quot;input.php&quot;&gt;
  &lt;b&gt; Richiedente Conferenza:&lt;/b&gt;&lt;br&gt;&lt;br&gt;
  Nome:&lt;input type=&quot;text&quot; name=&quot;name&quot; size=&quot;20&quot;&gt;&lt;br&gt;
  Cognome:&lt;input type=&quot;text&quot; name=&quot;surname&quot; size=&quot;20&quot;&gt;&lt;br&gt;
  Email: &lt;input type=&quot;email&quot; name=&quot;email&quot; size=&quot;20&quot;&gt;&lt;br&gt;
  Oggetto Conferenza:&lt;br&gt;&lt;textarea name=&quot;testo&quot; rows=&quot;5&quot; cols=&quot;40&quot; placeholder=&quot;Specificare oggetto Videoconferenza&quot;&gt;&lt;/textarea&gt;&lt;br&gt;
  
  &lt;br&gt;
  &lt;b&gt;Partecipanti Interni&lt;/b&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;div id=&quot;start&quot;&gt;
      &lt;div id=&quot;first&quot;&gt;
        Nome:&lt;input type=&quot;text&quot; name=&quot;iname[]&quot; size=&quot;20&quot;&gt;&lt;br&gt; 
        Cognome: &lt;input type=&quot;text&quot; name=&quot;isurname[]&quot; size=&quot;20&quot;&gt;&lt;br&gt; 
        Email: &lt;input type=&quot;email&quot; name=&quot;iemail[]&quot; size=&quot;20&quot;&gt;&lt;br&gt;
        &lt;br&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;br&gt;
   Numero partecipanti interni:
   &lt;input type=&quot;text&quot; id=&quot;n1&quot; value=&quot;1&quot;&gt;&lt;br&gt;
  
   &lt;button&gt;&lt;a href=&quot;#&quot; id=&quot;add&quot;&gt;Aggiungi partecipante&lt;/a&gt;&lt;/button&gt;
  
    
  
  &lt;br&gt;
  &lt;b&gt;Partecipanti Esterni&lt;/b&gt;
  &lt;br&gt;
  &lt;br&gt;
  Numero partecipanti Esterni:
   &lt;input type=&quot;text&quot; id=&quot;n2&quot; value=&quot;1&quot;&gt;&lt;br&gt;
  
   &lt;button&gt;&lt;a href=&quot;#&quot; id=&quot;add2&quot;&gt;Aggiungi partecipante&lt;/a&gt;&lt;/button&gt;
  
    &lt;div id=&quot;start2&quot;&gt;
      &lt;div id=&quot;first2&quot;&gt;
        Nome:&lt;input type=&quot;text&quot; name=&quot;ename[]&quot; size=&quot;20&quot;&gt;&lt;br&gt; 
        Cognome: &lt;input type=&quot;text&quot; name=&quot;esurname[]&quot; size=&quot;20&quot;&gt;&lt;br&gt; 
        Email: &lt;input type=&quot;email&quot; name=&quot;eemail[]&quot; size=&quot;20&quot;&gt;&lt;br&gt;
        &lt;br&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Invia&quot; &gt; 
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>And this is the input.php that i used to insert the data ( and also to connect to DB )</p>
  <pre><code>&lt;?php
  
  $conn = @pg_connect(&quot;dbname=postgres user=postgres password=123456789&quot;);
  
  if(!$conn) {
      die('Connessione fallita !&lt;br /&gt;');
  } else {
      echo 'Connessione riuscita !&lt;br /&gt;';
  }
  
  
  
  // Richiedente
  $name = $_POST['name'];
  $surname = $_POST['surname'];
  $email = $_POST['email'];
  $testo = $_POST['testo'];
  
  // Interni
  if($_POST['iname']) foreach($_POST['iname'] as $iname) 
  if($_POST['isurname']) foreach($_POST['isurname'] as $isurname)
  if($_POST['iemail']) foreach($_POST['iemail'] as $iemail)
  
  // Esterni
  if($_POST['ename']) foreach($_POST['ename'] as $ename) 
  if($_POST['esurname']) foreach($_POST['esurname'] as $esurname)    
  if($_POST['eemail']) foreach($_POST['eemail'] as $eemail)
  
  
  //inserting data order
  INSERT INTO prenotazioni  (id,nome_rich, cognome_rich, email_rich,oggetto_rich)
              VALUES (1,'$name','$surname', '$email','$testo');
  
  
  INSERT INTO interni (nome_int, cognome_int, email_int)
              VALUES ('$iname','$isurname','$iemail');
  
  INSERT INTO esterni  (nome_est, cognome_est, email_est)
              VALUES  ('$ename','$esurname','$eemail');
  
  
  
  ?&gt;
  </code></pre>
  <p>utils.js</p>
  <pre><code>$(document).ready(function() {
      $(&quot;#add&quot;).click(function(){
      
        var val1 =$(&quot;#n1&quot;).val();
        for(var i=0;i&lt;val1;i++){
        $(&quot;#start&quot;).append($(&quot;#first&quot;).clone());
        }
      });
  });
  
  $(document).ready(function() {
      $(&quot;#add2&quot;).click(function(){
      
        var val2 =$(&quot;#n2&quot;).val();
        for(var i=0;i&lt;val2;i++){
        $(&quot;#start2&quot;).append($(&quot;#first2&quot;).clone());
        }
      });
  });
  </code></pre>
  <p>I have test the connection to DB and i Receive the positive message ( in the echo ). But if i controll the tables they are empty.</p>