Welcome! Log In Create A New Profile

Advanced

The Portfolio student_reg.php

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
The Portfolio student_reg.php
September 29, 2013 11:17PM
Decided to created the topic to make it easier for everyone, myself included, to ask questions about this part of the portfolio.
Re: The Portfolio student_reg.php
September 29, 2013 11:24PM
Here is one of my posts that I have already posted under another topic. But since this is relevant to this specific topic, I decided to try and help to save everyone some time and include the post here again.

If anyone else is having trouble populating a drop-down list with date from MySQL, this video helped me quite a lot.
[video]http://www.youtube.com/watch?feature=player_embedded&v=nT0Wjt8ukZk[/video]
Re: The Portfolio student_reg.php
September 29, 2013 11:25PM
Again, a post I already posted elsewhere, I am repeating here in the hopes that it would help me and others taking the course.

I am stuck on my student_reg.php page. I have my form and all the info is going into the database table correctly. I am however really frustrated about the email. I do not know where to even start with that. All I know is that every tutorial simply uses the $mailsent=mail($to ,$subject, $message, $headers); line but this is not working!!!! I did take a look on the website recommended in the textbook (http://www.php.net/manual/en/function.mail.php) but I just feel completely out of my depth here.

My hope was to use Gmail to send the email (as my current computer has a Novell email installed that I cannot use for this course and installing outlook messes with my novell email). There are many posts on the internet about the Swift-mailer being able to send emails from your gmail, but I just get a horrible fatal error when I try that. I think I have to include the config.php file in there somewhere, but I have no clue as to where to start looking for that.

If anyone else has started with this, please share! Any help or a point in the right direction at this stage would be appreciated!
avatar Re: The Portfolio student_reg.php
September 29, 2013 11:45PM
The PHP mail() function sends the email from the server, so an email client on the users own computer, Gmail etc is totally irrelevant.

Bear in mind that the PHP mail() function is totally different from the HTML mailto() function, which does require an email client on the users computer.

The php.ini file has to be setup correctly to allow sending of email from the server.
avatar
Mac
Re: The Portfolio student_reg.php
September 30, 2013 09:28AM
Remember your installation of XAMPP is not connected to a real Internet mail server - it is a local "desktop-only" installation. If you run the mail() function on a real server it will work.

As said here ( http://osprey.unisa.ac.za/phorum/read.php?751,180013 ) I would not waste too much time on it. In general terms, it is easier to use a PHP mail class like http://phpmailer.codeworxtech.com/ (well, not as easy as using the built-in mail () function but once you get the hang of how to use it will manage more advanced issues you may have - like sending HTML in an email). For now, add a simple mail() function and see the error message that it is unable to send as a confirmation that code works - you are just not connected.
avatar Re: The Portfolio student_reg.php
September 30, 2013 09:44AM
It is easy to get mail() to work from your desktop installation -

You just have to make 2 changes to your php.ini file -

[mail function]
; For Win32 only.
SMTP = smtp.saix.net                  // <<< Enter your SMTP server here. 

; For Win32 only.
sendmail_from = your@emailaddress.co.za              // <<< Enter your e-mail address here.

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i" ).
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_paramaters =


This is for Windows running WAMP.
The semi-colons ; at the beginning of each line denotes a comment. Make sure you remove the semi-colons on the 2 affected lines.
avatar
Mac
Re: The Portfolio student_reg.php
September 30, 2013 02:01PM
If I remember correctly a few changes are required in sendmail.ini as well... and you need to be connected of course. Suppose that figures....
Re: The Portfolio student_reg.php
September 30, 2013 06:53PM
Thank you for clearing that up!

That means that I am actually almost finished with this page. smile

Just need to fix my validation so data would not insert in the database when there are errors.
avatar Re: The Portfolio student_reg.php
October 02, 2013 08:15PM
Sending PHP mail() with EasyPHP -

You only have to edit one line in php.ini to enable e-mailing from your EasyPHP installation.

From the EasyPHP FAQ -

The "mail" function from PHP returns an error (0) !
You need to replace this line: SMTP="localhost" in your PHP conf file (php.ini) by SMTP="mail.isp.com" where mail.isp.com stands for the mail server of your ISP.
Re: The Portfolio student_reg.php
October 06, 2013 11:08AM
Thank you Bigron11. Will definitely give it a shot! smile
Re: The Portfolio student_reg.php
October 07, 2013 11:11AM
Hi,

I have used $_SESSION for the Administrator log in. However, the student register page must allow the Student as well
as the Administrator access whether the Administrator is logged in or not. I need to know if the Administrator is logged in
as to use if statements to change the menu options for Student or Administrator.

regards
avatar Re: The Portfolio student_reg.php
October 07, 2013 12:06PM
This is a good idea. You can use an if else statement to display a different menu system for the currently logged in user.



78044545CharlesU Wrote:
-------------------------------------------------------
> Hi,
>
> I have used $_SESSION for the Administrator log
> in. However, the student register page must allow
> the Student as well
> as the Administrator access whether the
> Administrator is logged in or not. I need to know
> if the Administrator is logged in
> as to use if statements to change the menu
> options for Student or Administrator.
>
> regards

___________________________________________________________________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning...
Re: The Portfolio student_reg.php
October 09, 2013 11:18PM
Hi All

I am extremely behind, currently working on my student_reg.php to sent data to the database and for some reason it's not capturing the data in the database.

This is the code I am currently using:

<?php

//Sever details
$user_name="root"; //Mysql username
$password="password75"; //Mysql password
$database="registration"; //Database name
$server="127.0.0.1"; //Host name
$table_name="student"; //Table name

// Connect to server and select database
mysql_connect($server,$user_name,$password)
or die (" Cannot connect to Server"winking smiley;
$db_found = mysql_select_db($database)
or die ("Cannot connect to Database"winking smiley;

//Get vaules from form
$sname = $_POST ['sname'];
$init = $_POST ['init'];
$fname = $_POST ['fname'];
$title = $_POST ['title'];
$msname = $_POST ['msname'];
$dob = $_POST ['dob'];
$gen = $_POST ['gen'];
$lang = $_POST ['lang'];
$idno = $_POST ['idno'];
$telh = $_POST ['telh'];
$telw = $_POST ['telw'];
$cel = $_POST ['cel'];
$fax = $_POST ['fax'];
$email = $_POST ['email'];
$address = $_POST ['address'];
$contact_flag = $_POST ['contact_flag'];

// Insert data into mysql
$sql = "INSERT INTO $table_name(sname, init, fname, title, msname, dob, gen, lang,
idno, telh, telw, cel, fax, email, address, contact_flag)
VALUES('$sname', '$init', '$fname', '$title', '$msname', '$dob', '$gen', '$lang',
'$idno', '$telh', '$telw', '$cel', '$fax', '$email', '$address', '$contact_flag'winking smiley";
$result = mysql_query($sql);

// If successfully insert data into database, display message "Successful".
if ($result) {
echo "Student successfully registered";
}

else {
echo "ERROR";
}

?>

any help would be much appreciated, I keep getting "ERROR" so I know that the data isn't being captured successfully

Regards,

Milan
avatar
Mac
Re: The Portfolio student_reg.php
October 10, 2013 08:58AM
Add an "or die()" function after the sql db query to get more precise error information. Also post code using the format button (See tut letter).
avatar Re: The Portfolio student_reg.php
October 10, 2013 09:37AM
Some suggestions -

Put your DB connect code in a separate script and then "include" where required.
You use the same script several times, no need to repeat the same code every time.

No purpose in using a variable for the table name. All the fields are specific to that table, so the variable will never have any other value.

You should check that the $_POST array has been set before trying to extract values from it - "isset".
All $_POST['names'] identical to corresponding form input names ?

$sql = "INSERT INTO $table_name(sname, init, fname, title, msname, dob, gen, lang, // Use actual table name rather than variable.
Leave a space after the variable / table name. This is posssibly the error.
The variable name reads as - "$table_name(sname," instead of "$table_name".
avatar Re: The Portfolio student_reg.php
October 10, 2013 10:32AM
Not sure about this part. Did you check if there is no data in the database. Use phpMyAdmin and browse the table if any data is in it. From the code below you are using an if.. else. What should if($result) be?? Should it be true, false, 1 or 0?? Should be something like:

Language: PHP
if ($result = true) { echo "Student successfully registered"; } else { echo "Student not registered"; }




Language: PHP
// If successfully insert data into database, display message "Successful".     if ($result) { //Problem is here!! echo "Student successfully registered"; }   else { echo "ERROR"; }

___________________________________________________________________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning...
avatar Re: The Portfolio student_reg.php
October 10, 2013 10:54AM
mysql_query() returns TRUE or FALSE for an INSERT query.

So,

Language: PHP
if ($result) { // some code; }

is valid, no problem.
Re: The Portfolio student_reg.php
October 10, 2013 11:18AM
Hi Milan,

Just got a message from the private messaging facility, I don't think we are supposed to use it . We are all in this together, and help each other.
The best advice comes from Prof mac, Alexb and bigron are a great help in sending you to quick result sites. Suggest you start with buiding the
config.php file .See the textbook chapter 10 page 286. to see what the file should look like but use Tutorial PHP Thirteen 2. Reading records from a MySQL
database
to set it up then make a template to copy/paste from. Will save you hours when building test files!


Language: PHP
template.php   <?php require(';config.php';);   $db_handle=mysql_connect($server,$user_name,$password); $db_found=mysql_select_db($database,$db_handle);   ?>

This way you shouldn't get any more errors.

We're all hoping to meet the deadline, hoping to see you on the site daily, right to the end Regards CharlesU
Re: The Portfolio student_reg.php
October 10, 2013 09:58PM
Milan you only starting now?
Re: The Portfolio student_reg.php
October 10, 2013 11:27PM
Hi All

Thanks for your help, it's working like a charm.

@78185106 - Kind of my laptop crashed so got to start from scratch. but will forge ahead.

Thanks again everyone.
Re: The Portfolio student_reg.php
October 11, 2013 11:31AM
HI Milan. That is a bummer. Please feel free to ask for help!!! smiling smiley
Re: The Portfolio student_reg.php
October 17, 2013 04:29PM
Hi Guys,

I'm also started a bit late eye popping smiley, and thanks for the useful tips so far.

I need help, how do I insert data into the tables "student" and "course" at the same time?

I only managed to get them into "student".

Your help would be appreciated!

Warren
avatar Re: The Portfolio student_reg.php
October 17, 2013 04:45PM
This is how I did mine. Hope it helps:

Language: PHP
//Inserts student data into database conDB(); $sql = "INSERT INTO student (sname,init,fname,title,msname,dob,gen,lang,idno,telh,telw,cel,fax,email,address,contact_flag) VALUES (';$studSn';,';$studIn';,';$studFn';,';$studTit';,';$studMn';,';$studDob';,';$studGen';,';$studLan';,';$studId';, ';$studTelh';,';$studTelw';,';$studCell';,';$studFax';,';$studEmail';,';$studAdr';,';$studShare';)"; $result = mysql_query($sql) or die (mysql_error());   //Gets the value of the last record in the database $link = mysql_connect(sql_host,sql_user,sql_pass); $studNr = mysql_insert_id($link);   //Inserts student registration and course into database $sql1 = "INSERT INTO course_student (sno,cid, year) VALUES (';$studNr';,';$CourseA';,';$studYear';)"; $result2 = mysql_query($sql1) or die (mysql_error()); mysql_close();

Variable $CourseA comes from a value that the user selects from a drop down box.



Warren-78026563 Wrote:
-------------------------------------------------------
> Hi Guys,
>
> I'm also started a bit late eye popping smiley, and thanks for
> the useful tips so far.
>
> I need help, how do I insert data into the tables
> "student" and "course" at the same time?
>
> I only managed to get them into "student".
>
> Your help would be appreciated!
>
> Warren

___________________________________________________________________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning...
Re: The Portfolio student_reg.php
October 17, 2013 10:07PM
would like to see you $CourseA variable AlexB smiling smiley
Re: The Portfolio student_reg.php
October 17, 2013 10:08PM
did you do a foreach loop? Alexb
Re: The Portfolio student_reg.php
October 18, 2013 10:14AM
Thanks for the feedback Alex!

I'll see if i can make sense of that and wull get back to you soon!

Warren
avatar Re: The Portfolio student_reg.php
October 18, 2013 10:23AM
This is how my $CourseA variable gets it's value.

Language: PHP
//Check to see what was selected in dropdown boxes if (isset($_POST[';selCourse';])) { $CourseA = $_POST[';selCourse';]; }

selCourse is my dropdown box.

78185106 Wrote:
-------------------------------------------------------
> would like to see you $CourseA variable AlexB smiling smiley

___________________________________________________________________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning...
Re: The Portfolio student_reg.php
October 18, 2013 12:52PM
Hi there,

I know this was answered before but I can't seem to find it. How do you clear the student_reg.php page when
the Administrator has completed with the details of the one student and wants to enter the next student?

CharlesU
avatar Re: The Portfolio student_reg.php
October 18, 2013 02:12PM
You set all the variables to empty, after updating the database.

Eg:

$name = "";
Re: The Portfolio student_reg.php
October 18, 2013 09:21PM
Hi AlexB

I used Something way different.

Language: PHP
//Capturing the data PHP $studchoice= array(); foreach($_POST[';cname';] as $studcor){ $studchoice[]=($studcor); } $studchoice1= implode(';,';, $studchoice);   //drop down list. <select name="cname[]" multiple="multiple" > <option value=""></option> <?PHP connect(); dropdown();?> </select>*   // the function dropdown(); function dropdown(){ $sql="SELECT * FROM course"; $result=mysql_query($sql) or die(mysql_error()); while($record = mysql_fetch_assoc($result)){   echo';<option value="'; . $record[';cname';] . ';">'; . $record[';cname';] . ';</option>';; }   }

I created an array for the MULTIPLE selection of the drop down menu. In my SQL query is use $studchoice1.

I did try the code what you used but it only displayed one selected course out of the multiple selection in the database. what you think of my code?
avatar Re: The Portfolio student_reg.php
October 21, 2013 11:16AM
It looks good. I will try that some time. smile Shows you how many possibilities there are in programming.


78185106 Wrote:
-------------------------------------------------------
> Hi AlexB
>
> I used Something way different.
>
>
Language: PHP
> //Capturing the data PHP > $studchoice= array(); > foreach($_POST[';cname';] as $studcor){ > $studchoice[]=($studcor); > } > $studchoice1= implode(';,';, $studchoice); > > //drop down list. > <select name="cname[]" multiple="multiple" > > <option value=""></option> > <?PHP connect(); dropdown();?> > </select>* > > // the function dropdown(); > function dropdown(){ > $sql="SELECT * FROM course"; > $result=mysql_query($sql) or die(mysql_error()); > while($record = mysql_fetch_assoc($result)){ > > echo';<option value="'; . $record[';cname';] . ';">'; . > $record[';cname';] . ';</option>';; > } > > } > >
>
> I created an array for the MULTIPLE selection of
> the drop down menu. In my SQL query is use
> $studchoice1.
>
> I did try the code what you used but it only
> displayed one selected course out of the multiple
> selection in the database. what you think of my
> code?

___________________________________________________________________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning...
Re: The Portfolio student_reg.php
October 21, 2013 03:26PM
Hi,

A bit over my head at the moment. Working with it . Let you know the results!

Regards CharlesU
Re: The Portfolio student_reg.php
October 30, 2013 12:38PM
Hi there,

The email requirement! I've read all the questions and answers in this topic and I'm still in the dark, Trying the text book
but it doesn't make easy reading. I've seen something in the tutorial, but can't find it now. Where should I be looking?

CharlesU
avatar
Mac
Re: The Portfolio student_reg.php
October 30, 2013 12:56PM
You won't find if people post under a wrong topic like you are doing smiling smiley There is a lot here and in older forums... but what do you really want to know?
Re: The Portfolio student_reg.php
October 30, 2013 03:04PM
Hi Prof mac,

I really do have a genuine problem expressing myself, so i'm sorry if you misunderstand my questions. The following is
copied from page 9 in the tut letter.

3. Immediately after registration, the student receives an email confirming their registration. When a new student registers,
and email is sent to him and his classmates, the email containing an updated list of classmates’ names, surnames and emails.

Regards CharlesU
Re: The Portfolio student_reg.php
October 30, 2013 04:25PM
CharlesU,
There is a thread on the forum covering problems (and solutions) pertaining to sending emails. Please refer to these posts.
Regards,
Friedrich
Re: The Portfolio student_reg.php
October 31, 2013 06:46AM
Hi,

Thanks , that was what was the Topic and the Section of the Tutorial I was looking for. Overlooked it in my search.
The pressure is beginning to tell, I guess !!

Charlesu
avatar
Mac
Re: The Portfolio student_reg.php
October 31, 2013 11:52AM
78044545CharlesU Wrote:
-------------------------------------------------------
> Hi Prof mac,
>
> I really do have a genuine problem expressing
> myself, so i'm sorry if you misunderstand my
> questions.

Noe... I'm trying to keep order in the forum by suggesting you post the question under a correct topic or start a new topic - otherwise a lot of stuff is repeated... and people do not find it smiling smiley Anyway, you found the topic.
Sorry, only registered users may post in this forum.

Click here to login