can you suggest me the best solution to make multiple INSERT and UPDATE at the same time, please?
I use a SELECT to retrieve records from a table and I let the user to update the content of each record if he checks the checkbox "insert". At the moment, I use a form button for each set of records.
Since there can be lots of records, I would like to use only a single "form" and a single "form button" for all the data and to update or insert only the set of records when the user checks the checkbox. Is it possible? If yes, how? Can you give me any suggestions, please?
$sql = "select * from table1 where nome_area like '%$nome_area%' AND nome_voce like '%$nome_voce%'";
$rs = mysql_query( $sql ) or die('Database Error: ' . mysql_error());
$num = mysql_num_rows( $rs );
if($num >= 1 ){
echo "<table align=\"center\" cellspacing=0 cellpadding=100>";
echo "<tbody><tr><td width=\"20%\"> </td><td>";
while($row = mysql_fetch_array( $rs )){
echo "<form name=\"form\" id=\"form\" action=\"update.php\" method=\"post\">";
echo "<table data-role=\"table\" class=\"ui-responsive\" cellspacing=\"20\" ";
echo "<tbody>";
echo "<tr>";
echo "<td>";
echo "<font text color=\"red\">Insert</font> </td><td><input type=\"checkbox\" name=\"insert\" value=\"1\" id=\"insert\"></td></tr>";
echo "<tr><td><b>Tipo Area</b>:</td><td>".$row['nome_area']. " </td></tr><tr><td><b>Nome della voce</b>: </td><td> " .$row['nome_voce'] . "</td></tr>";
echo "<tr><td>";
echo "<input type=\"hidden\" style=\"width:0; height:0; border:0; background-color:inherit; overflow:hidden;\" name=\"id_voce\" maxlength=\"50\" value=\"" . $row['ID'] . "\">";
echo "<input type=\"hidden\" style=\"width:0; height:0; border:0; background-color:inherit; overflow:hidden;\" name=\"nome_azienda\" maxlength=\"50\" value=\"" .$name. "\">"; // azienda
echo "<input type=\"hidden\" style=\"width:0; height:0; border:0; background-color:inherit; overflow:hidden;\" name=\"nome_area\" maxlength=\"50\" value=\"" .$row['nome_area']. "\">";
echo "<input type=\"hidden\" style=\"width:0; height:0; border:0; background-color:inherit; overflow:hidden;\" name=\"nome_voce\" maxlength=\"50\" value=\"" .$row['nome_voce']. "\">";
echo "</td></tr>";
echo "<tr><td colspan=\"2\"> <input type=\"submit\" value=\"Associa la voce di contratto all'azienda\" id=\"search-btn\" style=\"height:50px; \"; /></td></tr>";
echo "</tbody></table>";
echo "</form>";
}
echo "</td></tr></tbody></table>";
}else{
// if no records found
echo "<br><br><b>Nessun risultato trovato!</b></div>";
}
In my update.php page, I just read the form values and INSERT them into my table:
.....
mysql_query("INSERT INTO table2 (id_voce,associazione, nome_azienda, nome_area, nome_voce, created_date) VALUES('$id_voce','$associa','$nome_azienda','$nome_area','$nome_voce','$time')");