Here is simple form contain multiple checkboxes options and textarea input:

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
    <table>
    <tr><th colspan="2">BREATHING CIRCULATION</th></tr>
    <tr><th>#</th><th>Instruction Name</th></tr>
    <tr><td><input name="InstrCheck[]" type="checkbox" id="InstrCheck" value="Respirations normal rate"></td><td>Respirations normal rate</td></tr>
    <tr><td><input name="InstrCheck[]" type="checkbox" id="InstrCheck" value="Respirations effort normal"></td><td>Respirations effort normal</td></tr>
<tr><td><input name="InstrCheck[]" type="checkbox" id="InstrCheck" value="Breath Sounds-normal"></td><td>Breath Sounds-normal</td></tr>
    <tr><td><input name="InstrCheck[]" type="checkbox" id="InstrCheck" value="Skin colour-normal"></td><td>Skin colour-normal</td></tr>
    <tr><td><input name="InstrCheck[]" type="checkbox" id="InstrCheck" value="Heart rhythm & rate normal"></td><td>Heart rhythm & rate normal </td></tr>
    <tr><td><input name="InstrCheck[]" type="checkbox" id="InstrCheck" value="No Oedema"></td><td>No Oedema </td></tr>
    </table>
    <textarea name="InstrCheck[]" id="InstrCheck" placeholder="set your own instruction">                          </textarea>
<input type="hidden" name="MM_insert" value="form1">
<input type="hidden" value="<?php echo $_GET['a'];?>" name="pat_id">
</form>

My problem is How can i insert checked options (could be more than one) AND textarea value (if entered) and insert all these inputs into same column in DB but each input in "separate row". I tried this code but not work :( inserting empty:

<?php
$editFormAction = $_SERVER['PHP_SELF'];
	if (isset($_SERVER['QUERY_STRING'])) {
  	$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
	}
	$pat_id = $_GET['a'];
	$Date = date("d-m-Y");
	$Time = date("H:i:s");
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
	foreach ($_POST['InstrCheck'] as $value) {
  $insertSQL = "INSERT INTO instruction (instName, instTime, instDate, pat_id) VALUES ('$value', '$Time', '$Date', '$pat_id')";
	}
  mysql_select_db($database_PPS, $PPS);
  $Result1 = mysql_query($insertSQL, $PPS) or die(mysql_error());
  

  $insertGoTo = "Patint_selection.php?a=$pat_id";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>

simple modification on php script make it works:

<?php 
$editFormAction = $_SERVER['PHP_SELF'];
	if (isset($_SERVER['QUERY_STRING'])) {
  	$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
	}
	$pat_id = $_GET['a'];
	$Date = date("d-m-Y");
	$Time = date("H:i:s");
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
	mysql_select_db($database_PPS, $PPS);
	foreach ($_POST['InstrCheck'] as $value) {
    $insertSQL = "INSERT INTO instruction (instName, instTime, instDate, pat_id) VALUES ('$value', '$Time', '$Date', '$pat_id')";
    $Result1 = mysql_query($insertSQL, $PPS) or die(mysql_error());
	}
  $insertGoTo = "Patint_selection.php?a=$pat_id";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
  
?>

:icon_lol:

This is great. Thanks for this syntaxes. I would like to use it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.