0

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>
1

1 Answer 1

1

You have $_POST['text'][$a] in your action but in html markup you have

<input type="text" required="required" maxlength="160" name="txt[]">

So you need either change name of html input to text or use $_POST['txt'][$a]

Other thing is that your code is vulnerable to SQL Injection. You should use prepared statements.

Sign up to request clarification or add additional context in comments.

1 Comment

Hey Tomasz, Thanks for your help the txt[] did the trick. I have used some hours and got lost in the woods??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.