jeudi 22 avril 2021

Multiple Check Boxes in PHP form inserted into MySQL

I know similar has been posted before, but nothing I can find is quite the same as my issue, even with me trying to adapt things.

I have a form with 28 checkboxes all named check[]

Along with three other fields on the form, I need this to insert a new record. I just can't work out how to iterate through the array and insert into the correct place. Any ideas appreciated.

I've also tried GetSQLValueString('check'[0]) etc and GetSQLValueString('check') etc

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
    
$selected = array();
if (isset($_POST['check']) && is_array($_POST['check'])) {
    $selected = $_POST['check'];
} else {
    $selected = array($_POST['check']);
}
    
  $insertSQL = sprintf("INSERT INTO checkin (`date`, `time`, room, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `13`, `14`, `15`, `16`, `17`, `18`, `19`, `20`, `21`, `22`, `23`, `24`, `25`, `26`, `27`, `28`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($_POST['time'], "date"),
                       GetSQLValueString($_POST['studio'], "int"),
                       GetSQLValueString($selected[0]),
                       GetSQLValueString($selected[1]),
                       GetSQLValueString($selected[2]),
                       GetSQLValueString($selected[3]),
                       GetSQLValueString($selected[4]),
                       GetSQLValueString($selected[5]),
                       GetSQLValueString($selected[6]),
                       GetSQLValueString($selected[7]),
                       GetSQLValueString($selected[8]),
                       GetSQLValueString($selected[9]),
                       GetSQLValueString($selected[10]),
                       GetSQLValueString($selected[11]),
                       GetSQLValueString($selected[12]),
                       GetSQLValueString($selected[13]),
                       GetSQLValueString($selected[14]),
                       GetSQLValueString($selected[15]),
                       GetSQLValueString($selected[16]),
                       GetSQLValueString($selected[17]),
                       GetSQLValueString($selected[18]),
                       GetSQLValueString($selected[19]),
                       GetSQLValueString($selected[20]),
                       GetSQLValueString($selected[21]),
                       GetSQLValueString($selected[22]),
                       GetSQLValueString($selected[23]),
                       GetSQLValueString($selected[24]),
                       GetSQLValueString($selected[25]),
                       GetSQLValueString($selected[26]),
                       GetSQLValueString($selected[27])
                      
                      );

  mysql_select_db($database_thepcguy_tilly, $thepcguy_tilly);
  $Result1 = mysql_query($insertSQL, $thepcguy_tilly) or die(mysql_error());



Aucun commentaire:

Enregistrer un commentaire