I have made this code and I can't get the $txt2 to be inserted into mysql! BUT the $tele2 is inserted, also when having multi rows from the dynamic form!.
But the $txt2 will not be inserted into DB.
Can someone see what the problem is. I think that it is some place in the foreach
This is the action post page!!
<?php if(isset($_POST)==true && empty($_POST)==false):
$day = $_POST['day'];
$month = $_POST['month'];
$text=$_POST['txt'];
$tele=$_POST['tele'];
include("db.php");
foreach($tele as $a => $b){
$a+1;
$txt2 = $_POST['text'][$a];
$tele2 = $_POST['tele'][$a];
$sql_ins="INSERT INTO SmsSend (`PHONENUM`, `TEXT`) VALUES
('".$tele2."','".$txt2."')";
$res_ins1=mysql_query($sql_ins);
}
?>
Sending my info from this dynamic form:
<fieldset class="row2">
<legend>Besked og bruger info</legend>
<p>
<input type="button" value="Tilføj bruger" onClick="addRow('dataTable')" />
<input type="button" value="Fjern bruger" onClick="deleteRow('dataTable')" />
</p>
<table id="dataTable" class="form" border="1">
<tbody>
<tr>
<td><input type="checkbox" required="required" name="chk[]" checked="checked" /></td>
<td>
<label for="txt">text</label>
<input type="text" required="required" maxlength="160" name="txt[]">
</td>
<td>
<label for="tele">TELE</label>
<input type="text" required="required" maxlength="8" name="tele[]">
</td>
</p>
</tr>
</tbody>
</table>
<div class="clear"></div>
</fieldset>
mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial. This problem is very solvable by employing prepared statements.