hi guys so i have this add contacts page and the form is divided into 3 different forms 1) primary contact 2)spouse and 3)child and the child form data is inserted as array into database because in the primary contact part of the form there is a “Children ?” with yes and no radio button and if yes a drop down list is enabled(1,2,3,4,5, etc…) where if user chooses say 2 then there would be 2 child form that appears and since there is 2 children then in the database a new row and data will be added accordingly.
image to be clearer:
[ATTACH]16145[/ATTACH]
i tried this:
[CODE]
<?php session_start();
if($_SESSION[‘sess_user_id’])
{
if(isset($_POST[‘submitC’]))
{
require “connection.php”;
$user = $_SESSION[‘sess_user_id’];
foreach($_POST[‘child-salutations’] as $index => $childsalutations)
{
$childsalutations = mysqli_real_escape_string($con, $index);
$childfname = mysqli_real_escape_string($con, $_POST[‘child-fname’][$index]);
$childlname = mysqli_real_escape_string($con, $_POST[‘child-lname’][$index]);
$cday = mysqli_real_escape_string($con, $_POST[‘cday’][$index]);
$cmonth = mysqli_real_escape_string($con, $_POST[‘cmonth’][$index]);
$cyear = mysqli_real_escape_string($con, $_POST[‘cyear’][$index]);
$chouse = mysqli_real_escape_string($con, $_POST[‘child-house’][$index]);
$cmobile = mysqli_real_escape_string($con, $_POST[‘child-mobile’][$index]);
$coffice = mysqli_real_escape_string($con, $_POST[‘child-office’][$index]);
$cemail = mysqli_real_escape_string($con, $_POST[‘child-email’][$index]);
if(preg_match(‘/^[a-zA-Zs]$/’, $childfname))
{
$a = ucwords($childfname);
if(preg_match(‘/^[a-zA-Zs]$/’, $childlname))
{
$b = ucwords($childlname);
if(preg_match(‘/^[+0-9-()s]*$/’, $cmobile))
{
if(preg_match(‘/^[+0-9-()s]*$/’, $coffice))
{
if(preg_macth(‘/^[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(.[a-zA-Z0-9-]+)*(.[a-zA-Z]{2,3})$/’, $cemail))
{
$add = “INSERT INTO child(chuser_id,child_id,c_name,c_dob,c_house,c_mobile,c_office,c_email) VALUES (‘$user’,”,’$childsalutations $childfname $childlname’,’$cday – $cmonth – $cyear ‘,’ $chouse ‘,’ $cmobile ‘,’ $coffice ‘,’ $cemail ‘)”;
$addchild = mysqli_query($con,$add) or die(mysqli_error());
if(!$addchild)
{
header(‘location : failed.php’);
}
else
{
header(‘location : event.php’);
}
}
}
}
}
}
}
}
}
?>
but it doesn’t seem to be working like it doesnt read the code, as in when the submit button is clicked it just refreshes and no database inserted.
this is the child form just incase someone wanted to c. its a bit long, shortened where unnecessary:
[CODE]
<div style=”visibility:hidden”>
<table class=”prime”>
<tbody>
<br>
<tr><td style=”font-size:20px;font-weight:bold”>Child <span id=”number”></span></td></tr>
<tr>
<td>Salutation :</td>
<td><select name=”child-salutations[]” >
<option value=”” disabled selected>Salutations</option>
<option value=”Datin”>Datin</option>
<option value=”Datin Paduka”>Datin Paduka</option>
</select>
</td>
</tr>
<tr><td>First Name :</td><td><input type=”text” name=”child-fname[]” class=”style” /></td>
<td>Last Name :</td><td><input type=”text” name=”child-lname[]” class=”style” /></td></tr>
<tr>
<td>Date of Birth : </td>
<td>
<select name=”cday[]”>
<option value=””selected disabled>Day</option>
<option value=”1″>1</option>
<option value=”2″>2</option>
<option value=”3″>3</option>
<option value=”4″>4</option>
</select>
<select name=”cmonth[]”>
<option value=”” selected disabled>Month</option>
<option value=”1″>January</option>
<option value=”2″>February</option>
<option value=”3″>March</option>
<option value=”4″>April</option>
</select>
Year : <input type=”text” name=”cyear[]” maxlength=”4″ size=”4″ class=”year”>
</td>
</tr>
<tr><td>House Address</td></tr>
<tr><td>Line 1 :</td><td><input type=”text” name=”child-house[]” size=”20″ class=”style” /></td>
<td>Mobile No :</td><td><input type=”text” name=”child-mobile[]” class=”style” maxlength=”20″/></td></tr>
<tr><td>Office No :</td><td><input type=”text” name=”child-office[]” class=”style” /></td>
<td>Email Address : </td><td><input type=”email” name=”child-email[]” class=”style” /></td></tr>
</tbody>
</table>
</div>
the table is in a hidden div because the table is cloned into the form when user chooses a number from the drop down list.
thanks in advance
[canned-message]attachments-removed-during-migration