Simplify MySQL INSERT query Is there a way to simplify the code below?  I want to simplify it, but I don't know if it is possible.

In the table below, I insert data which will end up in a MySQL table.

HTML

&lt;table border="0"&gt;
    &lt;tr&gt;
        &lt;td align="center"&gt;Dată / Interval orar&lt;/td&gt;
        &lt;td align="center"&gt;Denumire&lt;/td&gt;
        &lt;td align="center"&gt;Moderatori&lt;/td&gt;
        &lt;td align="center"&gt;Detalii&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td align="center"&gt;&lt;input name="DataInterval1" type="text" id="DataInterval1"&gt;&lt;/td&gt;
        &lt;td align="center"&gt;&lt;input name="Denumire1" type="text" id="Denumire1"&gt;&lt;/td&gt;
        &lt;td align="center"&gt;&lt;input name="Moderatori1" type="text" id="Moderatori1"&gt;&lt;/td&gt;
        &lt;td align="center"&gt;&lt;input name="Detalii1" type="text" id="Detalii1"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td align="center"&gt;&lt;input name="DataInterval2" type="text" id="DataInterval2"&gt;&lt;/td&gt;
        &lt;td align="center"&gt;&lt;input name="Denumire2" type="text" id="Denumire2"&gt;&lt;/td&gt;
        &lt;td align="center"&gt;&lt;input name="Moderatori2" type="text" id="Moderatori2"&gt;&lt;/td&gt;
        &lt;td align="center"&gt;&lt;input name="Detalii2" type="text" id="Detalii2"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    ...
    &lt;tr&gt;
        &lt;td align="center"&gt;&lt;input name="DataIntervaln" type="text" id="DataIntervaln"&gt;&lt;/td&gt;
        &lt;td align="center"&gt;&lt;input name="Denumiren" type="text" id="Denumiren"&gt;&lt;/td&gt;
        &lt;td align="center"&gt;&lt;input name="Moderatorin" type="text" id="Moderatorin"&gt;&lt;/td&gt;
        &lt;td align="center"&gt;&lt;input name="Detaliin" type="text" id="Detaliin"&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;


Part of the PHP code that I want to simplify:

$DataInterval1=$_POST['DataInterval1'];
$Denumire1=$_POST['Denumire1'];
$Moderatori1=$_POST['Moderatori1'];
$Detalii1=$_POST['Detalii1'];   
$DataInterval2=$_POST['DataInterval2'];
$Denumire2=$_POST['Denumire2'];
$Moderatori2=$_POST['Moderatori2'];
$Detalii2=$_POST['Detalii2'];
...
$DataIntervaln=$_POST['DataIntervaln'];
$Denumiren=$_POST['Denumiren'];
$Moderatorin=$_POST['Moderatorin'];
$Detaliin=$_POST['Detaliin'];   

// Insert data into mysql
$sql="INSERT INTO tabel (DataInterval, Denumire, Moderatori, Detalii)VALUES
('".$DataInterval1."', '".$Denumire1."', '".$Moderatori1."', '".$Detalii1."'),
('".$DataInterval2."', '".$Denumire2."', '".$Moderatori2."', '".$Detalii2."'),
... 
('".$DataIntervaln."', '".$Denumiren."', '".$Moderatorin."', '".$Detaliin."')";
$result=mysql_query($sql);
Use indexing in HTML name attributes

&lt;table&gt;
    &lt;tr&gt;
        &lt;td&gt;Dată / Interval orar&lt;/td&gt;
        &lt;td&gt;Denumire&lt;/td&gt;
        &lt;td&gt;Moderatori&lt;/td&gt;
        &lt;td&gt;Detalii&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;input name="DataInterval[0]" type="text" id="DataInterval1"&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="Denumire[0]" type="text" id="Denumire1"&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="Moderatori[0]" type="text" id="Moderatori1"&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="Detalii[0]" type="text" id="Detalii1"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    ...
    &lt;tr&gt;
        &lt;td&gt;&lt;input name="DataInterval[n]" type="text" id="DataIntervaln"&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="Denumire[n]" type="text" id="Denumiren"&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="Moderatori[n]" type="text" id="Moderatorin"&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="Detalii[n]" type="text" id="Detaliin"&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;


Use the indexing on the server side

&lt;?php
$data = array();
foreach ($_POST["DataInterval"] as $index =&gt; $value) {
    $data[] = array(
        "DataInterval" =&gt; $_POST["DataInterval"][$index],
        "Denumire" =&gt; $_POST["Denumire"][$index],
        "Moderatori" =&gt; $_POST["Moderatori"][$index],
        "Detalii" =&gt; $_POST["Detalii"][$index],
    );
}


After this you only have to iterate throught the $data array and execute paramtrized INSERT SQL commands.


do not use old mysql lib
learn about PDO and prepared statements