Email help
Posted: Fri Apr 22, 2011 2:53 am
Hi There
Basically I have this script that runs a few queries then emails the results.
It gets the $_POST['cid'] from this which is on the same page
The problem I'm having is if the value of cid is 0 I get this error.
Could not retrieve info from course_student for mail: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
I have tried adding if statements but then the mail() doesn't work. I've also tried changing this:
to
but then I get these errors:
Undefined variable: email in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 133
Undefined variable: fname in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 135
Undefined variable: sname in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 135
Undefined variable: cname in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 135
Undefined variable: text in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 135
Warning: mail() [function.mail]: SMTP server response: 503 5.5.2 Need Rcpt command. in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 136
Warning: Cannot modify header information - headers already sent by (output started at E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php:135) in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 137
lines 132 - 137 are
Any help would be appreciated 
Basically I have this script that runs a few queries then emails the results.
Code: Select all
if (isset($_POST['submit'])) {
$course_info = "SELECT sno, cid FROM course_student WHERE cid=".$_POST['cid'];
$course_info_result = mysql_query($course_info) or die ("Could not retrieve info from course_student for mail: " . mysql_error());
while($row_course_student = mysql_fetch_array($course_info_result)){
$sno = $row_course_student['sno'];
$cid = $row_course_student['cid'];
$student_info = "SELECT sno, fname, sname, email, contact_flag FROM student WHERE sno = $sno AND contact_flag = 'y' ORDER BY sno";
$result = mysql_query($student_info) or die ("Could not retrieve student info for mail: " . mysql_error());
$num = mysql_num_rows($result);
$i = 0;
while($i < $num){
$row = mysql_fetch_array($result);
$mail = $row['email'];
$fname = mysql_result($result, $i, 'fname');
$sname = mysql_result($result, $i, 'sname');
$email .= mysql_result($result, $i, 'email').",";
$text .= $fname . ' ' . $sname . ' - ' . $mail. "\n";
$i++;
}
$course_name = "SELECT cid, cname FROM course WHERE cid = $cid";
$course_name_query = mysql_query($course_name) or die ("Could not retrieve course name from database: " . mysql_error());
while($row_course = mysql_fetch_array($course_name_query)){
$cname = $row_course['cname'];
}
}
$from = 'From: Info <info@spargweb.co.za>' . "\r\n";
$to = $email;
$subject = "Successfully Registered";
$body = "Hi $fname $sname,\n\nHere is a list of all students currently studying $cname that are willing to be contacted for help\n\n$text";
mail($to, $subject, $body , $from);
header("location:student_man.php");
}
Code: Select all
$qry = "SELECT cid, cname FROM course ORDER BY cname ASC";
$result = mysql_query($qry) or die (mysql_error());
echo '<option value = "">Choose a Course</option>';
while ($row = mysql_fetch_array($result)) {
$cid = $row['cid'];
$cname = $row['cname'];
echo "<option value=$cid>$cname</option>";
}
Could not retrieve info from course_student for mail: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
I have tried adding if statements but then the mail() doesn't work. I've also tried changing this:
Code: Select all
echo '<option value = "">Choose a Course</option>Code: Select all
echo '<option value = "0">Choose a Course</option>Undefined variable: email in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 133
Undefined variable: fname in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 135
Undefined variable: sname in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 135
Undefined variable: cname in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 135
Undefined variable: text in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 135
Warning: mail() [function.mail]: SMTP server response: 503 5.5.2 Need Rcpt command. in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 136
Warning: Cannot modify header information - headers already sent by (output started at E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php:135) in E:\www\spargzco\spargweb.co.za\wwwroot\student_reg.php on line 137
lines 132 - 137 are
Code: Select all
$from = 'From: Info <info@spargweb.co.za>' . "\r\n";
$to = $email;
$subject = "Successfully Registered";
$body = "Hi $fname $sname,\n\nHere is a list of all students currently studying $cname that are willing to be contacted for help\n\n$text";
mail($to, $subject, $body , $from);
header("location:student_man.php");