Mysqli insert using a for loop

So I have a MySqli statement that both the option value columns name are changeable and so is the variables being inserted into the database and it’s saving the second set of values but not the first and was wondering where my for loop is going wrong.

This is the statement:

for($i=0; $i<sizeof($optionname); $i++)
{
$stmt = $mysqli->prepare("INSERT INTO cart (userid, itemno, option".($i+1)."name, option".($i+1)."value) VALUES (?, ?, ?, ?)");

    $stmt->bind_param('ssss', $CartID, $PartNo, $optionname[$i], $optionvalue[$i],);
}
$stmt->execute();

What is the rest of the code?

This is far easier to keep up with when you do not use the $_POST arrays.

Sponsor our Newsletter | Privacy Policy | Terms of Service