Please have a look Website interface
I only can insert these data with click both of the submit <button>
.
I wish to use only one submit <button>
to submit these data twice.
Here is my code.
As u can see, I for
loop this <form>
<?php
for($x=1; $x<=2; $x++)
{
?>
<div class="col-lg-6">
<label>Passenger <?php echo $x ?> </label>
<form role="form" method='post'>
<div class="form-group">
<label>Title</label>
<label class="radio-inline">
<input type="radio" name="gander" value="Mr" checked>Mr
</label>
<label class="radio-inline">
<input type="radio" name="gander" value="Ms">Ms
</label>
</div>
<div class="form-group">
<label>Enter name of Passenger</label>
<input class="form-control" name='name'>
</div>
<div class="form-group">
<label>Enter Passenger Id <?php echo $x ?></label>
<input class="form-control" placeholder="960529-01-6925" name='ic'>
</div>
<button type="submit" class="btn btn-default" name="addbtn" method="post">Submit Button</button>
</form>
</div>
<?php
}
?>
Here is the isset button code
<?php
if(isset($_POST["addbtn"]))
{
$ganderphp = $_POST["gander"];
$namephp = $_POST["name"];
$icphp = $_POST["ic"];
$sql = "INSERT INTO `passenger_data`(`pass_gender`,`pass_name`,`pass_ic`,`Username`) VALUES ('$ganderphp','$namephp','$icphp','$username')";
if (mysqli_query($conn, $sql)) {
echo $sql;
}else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
?>
Its not user friendly because user only can submit data on one of the form first. I did try to take the submit button out of the looping, but its not working. I need a solution to make user can submit only once for all these data.
Base on some research, maybe array[] and for each can done this but i just don know how to use it.
Appreciate for any answer.