Welcome! Log In Create A New Profile

Advanced

last minute questions

Posted by 77686160 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
last minute questions
October 28, 2012 08:30PM
I'm sure most of you have send in your project and good luck to all from me. I am stuck at the momemt with the Register student page as I can't get the sno and cid fields into the Student_course table from the registration form. This is my coding so far, can anyone help?
Also a silly question, where do I find the config file??

Language: PHP
<?PHP   $cname = $_POST[';cname';]; $SQL = "SELECT * FROM course WHERE course.cid =';$cname';"; $result = mysql_query($SQL); $numRows = mysql_num_rows($result); $boolLastRow = mysql_data_seek($result, ($numRows - 1)); $row = mysql_fetch_row($result); $cID = $row[0]; $cID++; $course_id = $cID;   $st_no = "SELECT * FROM student WHERE student.cid =';$cname';";   $db_handle = mysql_connect("localhost", "root" , "") or die("Could not connect: " . mysql_error()); mysql_select_db(';registration';, $db_handle) or die(mysql_error());         $studentsql = "INSERT INTO student (sname, init, fname, title, msname, dob, gen, lang, idno, telh, telw, cel, fax, email, address) VALUES (';$_POST[sname]';,';$_POST[init]';,';$_POST[fname]';,';$_POST[title]';,';$_POST[msname]';,';$_POST[dob]';,';$_POST[gen]';,';$_POST[lang]';,';$_POST[idno]';,';$_POST[telh]';,';$_POST[telw]';,';$_POST[cel]';,';$_POST[fax]';,';$_POST[email]';,';$_POST[address]';)";   $result = mysql_query($studentsql) or die("Invalid query: " . mysql_error());   $studentsql = "INSERT INTO course_student (sno, cid) VALUES (';$st_no';, ';$course_id';)";   $result = mysql_query($studentsql) or die("Invalid query: " . mysql_error());       if($result){ echo("<br>Data input is successfull"); } else{ echo("<br>Data input has failed"); }     ?>
avatar
Mac
Re: last minute questions
October 29, 2012 07:28AM
Mmmm, leaving it late. You create the config file yourself and include it.

The student info is inserted first. Get the student id that was created by the insert using the mysql_insert_id. You also have the course ID - you should have sent it with the registration form

Language: PHP
//sql query to get course names and course ids <input type=checkbox.... name=<?php echo "$course_name"; ?> value="$cid";?>...>

So the cid is sent, and you get the student is with the function above, then you have both and do a single insert.
Re: last minute questions
October 29, 2012 11:11AM
Hi, Mac. Thank you very much. The course was more difficult than I anticipated. Think I needed some background, but portfolio sent.
Thanks, Jenny
Re: last minute questions
October 29, 2012 11:13AM
Yeah thanks Mac and everyone, been a great experience doing things through UNISA and through this portal. Uploaded my project, hope its sufficient ... Wow long wait till the results lol ... Nerves indeed! Been awesome, can honestly say I am going to do another course for first semester next year smiling smiley
avatar Re: last minute questions
October 30, 2012 02:41PM
ok, so the deadline has come, I've just tested mine and my email functionality doesn't work. Here's the code for the function I created to send the email. Can anyone see what i've done wrong?

Language: PHP
function send_email($idno){ //send email to new student $sql_email_student = "SELECT fname, sname, email FROM student WHERE idno = ';$idno';"; $result = mysql_query($sql_email_student) or die(mysql_error()); while ($row = mysql_fetch_array($result)){ $to_student = $row[';email';]; $from = "admin@yournisa.co.za"; $subject = "Welcome"; $headers = "From: ".$from." "; $message = "Welcome $row[fname] $row[sname] to yournisa. We hope you would excel to your greatest potential!"; } mail($to_student, $subject, $message, $headers);   //send the updates to the rest of the students. $sql_email_class = "SELECT fname, sname, email FROM student"; $result_email_class = mysql_query($sql_email_class); $sql_shared = "SELECT fname, sname, email FROM student WHERE contact_flag = ';Y';"; $result_shared = mysql_query($sql_shared); $message_class = ""; while ($row_class = mysql_fetch_array($result_email_class)){ $message_class = ""; $to = $row_class[';email';]; $from = "admin@yournisa.co.za"; $subject = "Class information"; $headers = "From: ".$from." "; $message_class = "Hi $row_class[fname] $row_class[sname] </br>". "</br> Below is an updated list of your class mates</br>"; while ($row_shared = mysql_fetch_array($result_shared)){ $message_class .= "$row_shared[fname] $row_shared[sname] $row_shared[email] </br>"; } $message .= "Kind Regards </br>". "The Yournisa Team </br>"; mail($to, $subject, $message, $headers); } }
avatar
Mac
Re: last minute questions
October 30, 2012 03:05PM
As said in other threads, mail will not be sent from a XAMPP server as-is. If you did (no time to go back on threads to read if you did), I don't see obvious errors. but is is better to use a class like phpmailer.

See a tut here: http://www.askapache.com/php/phpfreaks-eric-rosebrocks-phpmailer-tutorial.html

Here is how it can be used in its simplest form

Language: PHP
require("class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsMail();     $mail->AddAddress($email); //$email from db query for example $mail->IsHTML(true); // if there is HTML in your email $mail->From="$from_email"; $mail->FromName="$sender_name"; $mail->Sender="$from_email"; // indicates ReturnPath header $mail->AddReplyTo("$from_email", "$from_email"); // indicates ReplyTo headers $mail->MsgHTML(true); // if there is HTML in your email   $mail->AddCC("jonny@there.com", "$other");   echo "<br>The following Email has been send to $manager_name ($man_email) at <strong>$club</strong> :<br><br>"; $body ="add body"; $body .="add more body"; $mail->Subject="Request"; echo "$body"; // just to see what is sent $mail->Body = $body;   if(!$mail->Send()) { echo "Error sending: " . $mail->ErrorInfo;; } else { echo "Sent!";   mysql_query here // insert a record of the sent email into a db }     $mail->ClearAddresses();
avatar Re: last minute questions
October 30, 2012 03:18PM
Thanks Mac. I'll test it out.
I'm not very familiar with classes yet tho, will start learning them now tho.
Sorry, only registered users may post in this forum.

Click here to login