Note that there are some explanatory texts on larger screens.

plurals
  1. POSending checkbox form array to email, formatting
    text
    copied!<p>I have three php pages. First is a selection.php page with options selected by checkboxes. On submit, the options are displayed and an email field (optional) to send the results to. The problem is in the email message's format. See below for code, email results, and ideal output. I appreciate anyone's help and time!</p> <p>selection.php <pre><code> $sqlSAT1 = "SELECT * FROM bandSched WHERE day='saturday' AND stage='stage 1'"; $sqlSAT2 = "SELECT * FROM bandSched WHERE day='saturday' AND stage='stage 2'"; $sqlSAT3 = "SELECT * FROM bandSched WHERE day='saturday' AND stage='stage 3'"; mysql_query($sqlSAT1); $result = mysql_query($sqlSAT1); while($row = mysql_fetch_array($result)) { echo "&lt;ul&gt;&lt;li&gt;"; echo'&lt;input type="checkbox" name="id[]" value="'.$row['id'].' " id="bandSched_' . $row['id'] . '" /&gt;'; echo '&lt;label for="bandSched_' . $row['id'] . '"&gt;' . $row['timeShow']." ".$row['bandName'] . '&lt;/label&gt;'; echo "&lt;/li&gt;&lt;/ul&gt;"; } ?&gt; </code></pre> <p>results.php</p> <pre><code> &lt;?php if ( ! empty($_POST['id'])) { foreach($_POST['id'] as $key =&gt; $id) { $_POST['id'][$key] = mysql_real_escape_string($_POST['id'][$key]); } $in = implode(', ', $_POST['id']); $sqlSAT1 = "SELECT * FROM bandSched WHERE day='saturday' AND stage='stage 1' AND id IN ($in) ORDER BY FIELD(id, $in)"; $result = mysql_query($sqlSAT1) or die('MySQL Error ' . mysql_errno() . ': ' . mysql_error()); } if ( ! isset($result)) { echo 'You did not select anything'; } else { while ($row=mysql_fetch_assoc($result)) { echo "&lt;tr&gt;"; echo "&lt;td&gt;". $row['timeShow'] ."&lt;/td&gt;&lt;td&gt;" . $row['bandName'] . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } } ?&gt; </code></pre> <p>and EmailProcess.php</p> <pre><code> &lt;?php $to = $_POST["email"]; $subject = "This is subject"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers .= "From:abc@somedomain.com \r\n"; foreach($_POST as $key =&gt; $value){ if(!(!isset($value))){$set=1;} if(is_array($value)){ $message = $message . "$key: ".implode( ', ', $value)."\n\n"; } else { $message = $message . "$key: $value\n\n"; } } $retval = mail ($to,$subject,$message,$headers); if( $retval == true ) { echo "Message sent successfully..."; } else { echo "Message could not be sent..."; }?&gt; </code></pre> <p>Finally, this is what the actual email with results looks like- </p> <pre><code> divcontent: &lt;div class=\"saturdaySched full_width light_gray\"&gt; &lt;div style=\"padding:20px\"&gt; &lt;h2&gt;SATURDAY&lt;/h2&gt; &lt;div id=\"stage1sat\" class=\"stageBox\"&gt; &lt;h3&gt;STAGE 1&lt;/h3&gt; &lt;table&gt; &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;11:30&lt;/td&gt;&lt;td&gt;G.Wizz&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;12:20&lt;/td&gt;&lt;td&gt;Sideshow Tramps&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1:40&lt;/td&gt;&lt;td&gt;Clap Your Hands Say Yeah&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;div id=\"stage2sat\" class=\"stageBox\"&gt; &lt;h3&gt;STAGE 2&lt;/h3&gt; &lt;table&gt; &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;12:00&lt;/td&gt;&lt;td&gt;The Wheel Workers&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;2:20&lt;/td&gt;&lt;td&gt;Starfucker&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;3:40&lt;/td&gt;&lt;td&gt;Phantogram&lt;/td&gt;&lt;/tr&gt; </code></pre> <p>Ideal email format could be as simple as a list (or something similar)</p> <pre><code>Stage 1- band1 2:30 Stage 1- band5 3:30 Stage 2- band4 3:10 etc... </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload