I've written a script that contains a form where the user selects recipients of a message by highlighting them in a drop down menu and clicking a button named "Add recipient". The script is as follows: session_start(); $ad_no = $_GET['ad_no']; $sql = "SELECT * FROM `Teacher` WHERE `ST_Username` = '" . $_SESSION['username'] . "'"; include("../includes/php/connect.php"); while ($row = mysql_fetch_assoc($rst)) { $current_teacher_code = $row['ST_Code']; } $sql2 = "SELECT * FROM `Student` WHERE PU_AdNo = '" . $ad_no . "'"; include("../includes/php/connect2.php"); while ($row2 = mysql_fetch_assoc($rst2)) { $forename = $row2['PU_Forename']; $surname = $row2['PU_Surname']; $tutor = $row2['PU_TutorGroup']; $photo = $row2['PU_Photopath']; $pu_year = $row2['PU_Year']; } if($pu_year == "9") { $year = "09"; } else { $year = $pu_year; } echo "<table width = '600' cellpadding = '0' border = '0'>"; echo "<tr>"; echo "<th width = '380' align = 'left'>"; echo "<font face = 'arial' size = '2'>" . $surname . " " . $forename ."</font>"; echo "</th>"; echo "<th width = '120'>"; echo "<font face = 'arial' size = '2'>" . $year . $tutor . "</font>"; echo "</th>"; echo "<td width = '100'>"; echo "<img src=\images/rms/sleepaz/" . $photo .">"; echo "</td>"; echo "</tr>"; echo "</table>"; $sql2 = "SELECT `CS_CL_ClassName` FROM `ClassStudent` WHERE CS_PU_AdNo = '" . $ad_no . "'"; include("../includes/php/connect2.php"); while ($row2 = mysql_fetch_assoc($rst2)) { $classes[] = $row2['CS_CL_ClassName']; } ?> <form action = "<?php echo $PHP_SELF; ?>" method = "post" /> <table width = "600" border = "0" cellpadding = "0" cellspacing = "0"> <tr> <th align = "left" width = "5%"> <font face = "arial" size = 2>To:</font> </th> <td align = "left" width = "95%"> <select name = "select_recipient"> <?php foreach ($classes as $a_class) { if ($_POST['select_recipient']) { $for_all_recipients = split(" - ",$_POST['recipients']); } $sql = "SELECT DISTINCT `CL_Subject`, `ST_Code`, `ST_Surname`, `ST_Forename` FROM `Class`, `TeacherClass`, `Teacher` WHERE Class.CL_ClassName = TeacherClass.TC_CL_ClassName AND Teacher.ST_Code = TeacherClass.TC_ST_Code AND Class.CL_ClassName = '" . $a_class . "' AND Teacher.ST_Code != '" . $current_teacher_code . "'"; include("../includes/php/connect.php"); while ($row = mysql_fetch_assoc($rst)) { $elements[] = $row['CL_Subject'] . ": " . $row['ST_Surname'] . ", " . $row['ST_Forename'] . " - (" . $row['ST_Code'] . ")"; } } for ($i=0; $i < count($elements); $i++) { ?> <option value = "<?php echo $row['ST_Code']; ?>"><?php echo $elements[$i]; ?></option> <?php } ?> </select> <input type = "submit" name = "add_recipient" value = "Add recipient" /> <?php if (isset($_POST['select_recipient'])) { ?> <input type = "hidden" name = "recipients" value = "<?php $all_recipients = $_POST['recipients'] ." - ". $_POST['select_recipient']; echo $all_recipients; ?>" /> <?php } ?> <input type = "button" width = "1" value = "Remove recipient" onClick = "javascript:history.back(-1)" /> </td> </tr> </table> <table width = "600" border = "0" cellpadding = "0" cellspacing = "0"> <tr> <td> <br /> </td> </tr> <tr> <td align = "left" width = "15%"> <strong><font size="2" face = "arial">Recipient(s):</font></strong> </td> <th align = "left" width = "80%"><font face = "arial" size = "2"><font color="#006600"> <?php if ($_POST['select_recipient']) { $for_all_recipients = split(" - ",$_POST['recipients']); /*if (is_null($recipients)) { echo "<td>You have not selected any recipients!</td>"; }*/ foreach ($for_all_recipients as $a_recipient) { echo $a_recipient." "; echo " | "; echo " "; } echo ($_POST['select_recipient']); } echo "</font>"; echo "</th>"; echo "</tr>"; echo "</form>"; echo "<tr>"; echo "<td>"; echo "<br />"; echo "</td>"; echo "</tr>"; echo "<form method = 'post' action = 'send_individual_msg.php?all_recipients=$all_recipients'>"; echo "<tr>"; echo "<th align = 'left'>"; echo "<font face = 'arial' size = '2'>Subject:</font> "; echo "</th>"; echo "<td align = 'left'>"; echo "<input type = 'text' name = 'subject' size = '75' maxlength = '75' />"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "<br />"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<th align = 'left'>"; echo "<font face = 'arial' size = '2' >Message:</font> "; echo "</th>"; echo "<td>"; echo "<textarea name = 'message' cols = '57' rows = '10' /></textarea>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "<br />"; echo "<br />"; echo "</td>"; echo "<td>"; echo "<input type = 'submit' name = 'submit' value = 'Send message' />"; echo "</td>"; echo "</tr>"; echo "<table>"; echo "</form>"; PHP: The highlighted option is not added to the array or printed to the screen when the "Add recipient" button is clicked. Also, when the mouse is held over the button the following link is displayed, which I cannot figure out why: "http://*****************/***/**/homepage/teacher_msg.php?ad_no=6645" The dashes which are supposed to split up the array by separating each individual element are added to array. Any ideas?
i don't actually see the function which would execute your sql, such as mysql_query($query)... $query = "SELECT * FROM Teacher"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { //other code goes here... }