karl_murphy
Apr 28th 2008, 2:07 am
Hi,
The following script selects a set of usernames from a database and prints them to the screen with a checkbox. The user can the select individual usernames and when they click the "Add recipient" button these our printed to the screen. The code is as follows:
<?php
session_start();
if($_SESSION['login_status'] != "success")
{
$sql = "INSERT INTO `RMS_Access` ( `ACC_ID` , `ACC_User` , `ACC_IP` , `ACC_Timestamp` , `ACC_Page` , `ACC_Type` )
VALUES (NULL , '" . $_SESSION['username'] . "', '" . $_SERVER['REMOTE_ADDR'] . "', NOW( ) , '" . $_SERVER['SCRIPT_NAME'] . "?class=" . $_GET['class'] . "', 'UNAUTH_ACCESS')";
include("../includes/php/connect.php");
Header("Location: http://www.thedatacentre.org/rms/v2/homepage/logout.php");
}
$sql = "INSERT INTO `RMS_Access` ( `ACC_ID` , `ACC_User` , `ACC_IP` , `ACC_Timestamp` , `ACC_Page` , `ACC_Type` )
VALUES (NULL , '" . $_SESSION['username'] . "', '" . $_SERVER['REMOTE_ADDR'] . "', NOW( ) , '" . $_SERVER['SCRIPT_NAME'] . "?class=" . $_GET['class'] . "', 'AUTH_ACCESS')";
include("../includes/php/connect.php");
$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'];
}
if ($_POST['select_recipient'])
{
$for_all_recipients = split(" - ",$_POST['recipients']);
}
$ad_no = $_GET['ad_no'];
$sql = "SELECT * FROM `Student`
WHERE PU_AdNo = '" . $ad_no . "'";
include("../includes/php/connect.php");
while ($row = mysql_fetch_assoc($rst))
{
$forename = $row['PU_Forename'];
$surname = $row['PU_Surname'];
$tutor = $row['PU_TutorGroup'];
$photo = $row['PU_Photopath'];
$pu_year = $row['PU_Year'];
}
if($pu_year == "9")
{
$year = "09";
}
else
{
$year = $pu_year;
}
echo "<table width = '600' cellpadding = '0'>";
echo "<tr>";
echo "<th width = '400' align = 'left'>";
echo "<font face = 'arial'>" . $surname . " " . $forename ."</font>";
echo "</th>";
echo "<th width = '100'>";
echo "<font face = 'arial'>" . $year . $tutor . "</font>";
echo "</th>";
echo "<td width = '100'>";
echo "<img src=\images/rms/sleepaz/" . $photo .">";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table cellpadding = '0'>";
echo "<tr>";
?>
<form method = "post" action = "<?php echo $PHP_SELF; ?>">
<?php
$sql2 = "SELECT * FROM `ClassStudent`
WHERE CS_PU_AdNo = '" . $ad_no . "'";
include("../includes/php/connect2.php");
while ($row2 = mysql_fetch_assoc($rst2))
{
$classes[] = $row2['CS_CL_ClassName'];
}
foreach ($classes as $a_class)
{
$sql = "SELECT DISTINCT Class.CL_Subject, TeacherClass.TC_ST_Code
FROM Class, TeacherClass
WHERE Class.CL_ClassName = TeacherClass.TC_CL_ClassName
AND Class.CL_ClassName = '" . $a_class . "'
AND TeacherClass.TC_ST_Code != '" . $current_teacher_code . "'";
include("../includes/php/connect.php");
while ($row = mysql_fetch_assoc($rst))
{
$subject = $row['CL_Subject'];
$teacher = $row['TC_ST_Code'];
echo "<th align = 'left' width = '200'>";
echo "<font face = 'arial'>" . $subject . "</font>";
echo "</th>";
echo "<th align = 'left' width = '100'>";
echo "<font face = 'arial'>" . $teacher . "</font>";
echo "</th>";
echo "<td>";
echo "<input type = 'checkbox' value = $teacher name = 'select_recipient' unchecked>";
echo "</td>";
echo "</tr>";
}
}
echo "<tr>";
echo "<td>";
echo "<br />";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<input type = 'submit' name = 'add_recipient' value = 'Add recipent' />";
if (isset($_POST['select_recipient']))
{
?>
<input type = "hidden" name = "recipients" value = "<?php $all_recipients = $_POST['recipients'] ." - ". $_POST['select_recipient']; echo $all_recipients; ?>" />
<?php }
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<br />";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table cellpadding = '0'>";
echo "<tr>";
echo "<th align = 'right'>";
echo "<font face = 'arial'>Recipients:</font> ";
echo "</th>";
echo "<th align = 'left'><font face = 'arial'><font color = '#006600'>";
if ($_POST['select_recipient'])
{
$teacher_array = $_POST['recipients'];
foreach ($teacher_array as $teacher)
{
echo $teacher;
echo " ";
}
echo ($_POST['select_recipient']);
}
echo "</font></th>";
echo "</tr>";
echo "</form>";
echo "<tr>";
echo "<td>";
echo "<br />";
echo "</td>";
echo "</tr>";
echo "<form method = 'post' action = 'send_teacher_msg.php?all_recipients=$all_recipients'>";
echo "<tr>";
echo "<th align = 'right'>";
echo "<font face = 'arial'>Subject:</font> ";
echo "</th>";
echo "<td>";
echo "<input type = 'text' name = 'subject' size = '75' maxlength = '75' />";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<th align = 'right'>";
echo "<font face = 'arial'>Message:</font> ";
echo "</th>";
echo "<td>";
echo "<textarea name = 'message' cols = '57' rows = '10'></textarea>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "</td>";
echo "<td>";
echo "<input type = 'submit' name = 'submit' value = 'Send message' />";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
?>
However, when the "Add recipient" button is clicked the following error message is displayed:
Warning: Invalid argument supplied for foreach() in /home/tben2505/public_html/rms/v2/homepage/teacher_msg.php on line 139
any ideas?
The following script selects a set of usernames from a database and prints them to the screen with a checkbox. The user can the select individual usernames and when they click the "Add recipient" button these our printed to the screen. The code is as follows:
<?php
session_start();
if($_SESSION['login_status'] != "success")
{
$sql = "INSERT INTO `RMS_Access` ( `ACC_ID` , `ACC_User` , `ACC_IP` , `ACC_Timestamp` , `ACC_Page` , `ACC_Type` )
VALUES (NULL , '" . $_SESSION['username'] . "', '" . $_SERVER['REMOTE_ADDR'] . "', NOW( ) , '" . $_SERVER['SCRIPT_NAME'] . "?class=" . $_GET['class'] . "', 'UNAUTH_ACCESS')";
include("../includes/php/connect.php");
Header("Location: http://www.thedatacentre.org/rms/v2/homepage/logout.php");
}
$sql = "INSERT INTO `RMS_Access` ( `ACC_ID` , `ACC_User` , `ACC_IP` , `ACC_Timestamp` , `ACC_Page` , `ACC_Type` )
VALUES (NULL , '" . $_SESSION['username'] . "', '" . $_SERVER['REMOTE_ADDR'] . "', NOW( ) , '" . $_SERVER['SCRIPT_NAME'] . "?class=" . $_GET['class'] . "', 'AUTH_ACCESS')";
include("../includes/php/connect.php");
$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'];
}
if ($_POST['select_recipient'])
{
$for_all_recipients = split(" - ",$_POST['recipients']);
}
$ad_no = $_GET['ad_no'];
$sql = "SELECT * FROM `Student`
WHERE PU_AdNo = '" . $ad_no . "'";
include("../includes/php/connect.php");
while ($row = mysql_fetch_assoc($rst))
{
$forename = $row['PU_Forename'];
$surname = $row['PU_Surname'];
$tutor = $row['PU_TutorGroup'];
$photo = $row['PU_Photopath'];
$pu_year = $row['PU_Year'];
}
if($pu_year == "9")
{
$year = "09";
}
else
{
$year = $pu_year;
}
echo "<table width = '600' cellpadding = '0'>";
echo "<tr>";
echo "<th width = '400' align = 'left'>";
echo "<font face = 'arial'>" . $surname . " " . $forename ."</font>";
echo "</th>";
echo "<th width = '100'>";
echo "<font face = 'arial'>" . $year . $tutor . "</font>";
echo "</th>";
echo "<td width = '100'>";
echo "<img src=\images/rms/sleepaz/" . $photo .">";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table cellpadding = '0'>";
echo "<tr>";
?>
<form method = "post" action = "<?php echo $PHP_SELF; ?>">
<?php
$sql2 = "SELECT * FROM `ClassStudent`
WHERE CS_PU_AdNo = '" . $ad_no . "'";
include("../includes/php/connect2.php");
while ($row2 = mysql_fetch_assoc($rst2))
{
$classes[] = $row2['CS_CL_ClassName'];
}
foreach ($classes as $a_class)
{
$sql = "SELECT DISTINCT Class.CL_Subject, TeacherClass.TC_ST_Code
FROM Class, TeacherClass
WHERE Class.CL_ClassName = TeacherClass.TC_CL_ClassName
AND Class.CL_ClassName = '" . $a_class . "'
AND TeacherClass.TC_ST_Code != '" . $current_teacher_code . "'";
include("../includes/php/connect.php");
while ($row = mysql_fetch_assoc($rst))
{
$subject = $row['CL_Subject'];
$teacher = $row['TC_ST_Code'];
echo "<th align = 'left' width = '200'>";
echo "<font face = 'arial'>" . $subject . "</font>";
echo "</th>";
echo "<th align = 'left' width = '100'>";
echo "<font face = 'arial'>" . $teacher . "</font>";
echo "</th>";
echo "<td>";
echo "<input type = 'checkbox' value = $teacher name = 'select_recipient' unchecked>";
echo "</td>";
echo "</tr>";
}
}
echo "<tr>";
echo "<td>";
echo "<br />";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<input type = 'submit' name = 'add_recipient' value = 'Add recipent' />";
if (isset($_POST['select_recipient']))
{
?>
<input type = "hidden" name = "recipients" value = "<?php $all_recipients = $_POST['recipients'] ." - ". $_POST['select_recipient']; echo $all_recipients; ?>" />
<?php }
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<br />";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table cellpadding = '0'>";
echo "<tr>";
echo "<th align = 'right'>";
echo "<font face = 'arial'>Recipients:</font> ";
echo "</th>";
echo "<th align = 'left'><font face = 'arial'><font color = '#006600'>";
if ($_POST['select_recipient'])
{
$teacher_array = $_POST['recipients'];
foreach ($teacher_array as $teacher)
{
echo $teacher;
echo " ";
}
echo ($_POST['select_recipient']);
}
echo "</font></th>";
echo "</tr>";
echo "</form>";
echo "<tr>";
echo "<td>";
echo "<br />";
echo "</td>";
echo "</tr>";
echo "<form method = 'post' action = 'send_teacher_msg.php?all_recipients=$all_recipients'>";
echo "<tr>";
echo "<th align = 'right'>";
echo "<font face = 'arial'>Subject:</font> ";
echo "</th>";
echo "<td>";
echo "<input type = 'text' name = 'subject' size = '75' maxlength = '75' />";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<th align = 'right'>";
echo "<font face = 'arial'>Message:</font> ";
echo "</th>";
echo "<td>";
echo "<textarea name = 'message' cols = '57' rows = '10'></textarea>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "</td>";
echo "<td>";
echo "<input type = 'submit' name = 'submit' value = 'Send message' />";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
?>
However, when the "Add recipient" button is clicked the following error message is displayed:
Warning: Invalid argument supplied for foreach() in /home/tben2505/public_html/rms/v2/homepage/teacher_msg.php on line 139
any ideas?