Still trying to get my head around submitting arrays and using Mysqli.
So on a form I want to have several inputs:
<form action='newmem2.php' method='post'>
<input type="text" name="memname[1]"><br>
<input type="text" name="memname[2]"><br>
<input type="text" name="memname[3]"><br>
<input type='submit' value='submit'>
</form>
then on newmem2.php I have:
$newmember = $_POST['memname'];
$sql = 'insert into members (name,active)values(?,?)';
$update = $db->prepare($sql);
foreach($newmember as $memname => $val) {
$update->bind_param('si', $val, '1');// the 1 indicates I want to force that
entry.
$update->execute();
}
the print_r($_post) revelas:
Array ( [memname] => Array ( [1] => joe [2] => bob [3] => eric ) )
but there isn't anything submitted to the database. (yes I have a valid connection). Searches indicate usage of
Also, if I only have one name entered, how can I go about skipping the remaining fields so I am not submitting empties?