What i am trying to do is to select a tutor from the list and send the email but like you said it sends the email to the last tutor of the list dont I just need if option value has been selected wouldnt that be much easier rather than having a javascript?
Note : I re-edited the code and inserted everything into the php
PHP Code:
<?php
session_start();
$link = mysql_connect('********', '********', '********');
mysql_select_db('********');
if($_SESSION['student_id'])
$studentID=$_SESSION['student_id'];
$query = mysql_query("Select * from students where Student_ID='$studentID'");
while($row=mysql_fetch_assoc($query))
{
$studentemail=$row['Student_Email'];
}
//echo "The student email is: $studentemail";
echo "<form action='testing.php' method='POST'>";
echo "<br>";
$result3 = mysql_query("SELECT * from tutors") or die(mysql_error());
while ($rows = mysql_fetch_assoc($result3))
{
//$tutorFname=$rows["Tutor_FName"];
//$tutorLname=$rows["Tutor_LName"];
$tutoremail=$rows['Tutor_Email'];
$options.= '<option value="'.$rows['Tutor_ID'].'">'.$rows['Tutor_FName']." ".$rows['Tutor_LName'].'</option>';
}
echo "<select name=Tutor_Email>";
echo "<option value=''>Choose</option>";
echo $options;
echo "</select>";
echo "<input type='submit' name='submit' value = 'Send Email'>";
echo "</form>";
$submit=$_POST['submit'];
if($submit)
{
if($options)
{
mail($tutoremail,"message","title","From:$studentemail");
echo "Message has been sent";
}
else
{
echo "select a tutor";
}
}
?>