i have a php for each loop that post only one record to database and it does not return any errors. i have checked my html and obviously there's nothin wrong it. i tried some SO options but still no results. here is my html
<form method="post" action="index.php">
<input type="text" name="username[]" value="12345" readonly="readonly" />
<input type="text" name="school[]" value="Degree" readonly="readonly" />
<select name="candname[]">
<option></option>
<option>wayne roony</option>
<option>ikpa oludo</option>
<option>meta</option>
<option>databoy</option>
<option>lanre</option>
<option>toafeek</option>
<option>shola suni</option>
</select>
<br/>
<select name="candname[]">
<option></option>
<option>wayne roony</option>
<option>ikpa oludo</option>
<option>meta</option>
<option>databoy</option>
<option>lanre</option>
<option>toafeek</option>
<option>shola suni</option>
</select>
<br/>
<select name="candname[]">
<option></option>
<option>wayne roony</option>
<option>ikpa oludo</option>
<option>meta</option>
<option>databoy</option>
<option>lanre</option>
<option>toafeek</option>
<option>shola suni</option>
</select>
<br/>
<select name="candname[]">
<option></option>
<option>wayne roony</option>
<option>ikpa oludo</option>
<option>meta</option>
<option>databoy</option>
<option>lanre</option>
<option>toafeek</option>
<option>shola suni</option>
</select>
<br/>
<select name="candname[]">
<option></option>
<option>wayne roony</option>
<option>ikpa oludo</option>
<option>meta</option>
<option>databoy</option>
<option>lanre</option>
<option>toafeek</option>
<option>shola suni</option>
</select>
and my PHP
<?php
$con=mysqli_connect("localhost","root","4***","online**");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
{
$username = $_POST['username'];
$school = $_POST['school'];
$candname = $_POST['candname'];
for ($i = 0; $i < count($username); $i++) {
$username = ($username[$i]);
$school = ($school[$i]);
$candname = ($candname[$i]);
mysqli_query($con, "INSERT INTO parlia_votes (username, school, candname) VALUES ('$username', '$school', '$candname')");
}
}
?>
my aim is to post all five selected options to the database. thanks for the help
formhave only oneusernamefield.