Welcome! Log In Create A New Profile

Advanced

Assignment 2 - Databse Design

Posted by wsbraun 
Announcements Last Post
Announcement myUnisa availability 21 to 24 March 2019 03/17/2019 02:24PM
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
avatar
Mac
Re: Assignment 2 - Databse Design
April 14, 2011 02:37PM
No - tsotsis can't do anything with it smiling smiley BUT read the security docs on the CD particularly the mysql_real_escape_string function. Use it.
Re: Assignment 2 - Databse Design
April 14, 2011 03:00PM
LOL smiling bouncing smiley cyber tsotsi. Thanks Mac
avatar Re: Assignment 2 - Databse Design
April 15, 2011 03:42PM
Hey guys. How do you go about specifying the directory path for a .php file thats in a different folder when using the include function? Having some difficulty with this.
Re: Assignment 2 - Databse Design
April 15, 2011 06:12PM
Use the / to separate the directories relative to the page

Language: PHP
include 'includes/session.inc';

one problem I had is that the include is relative to the first script. Not sure how to describe this exactly but here goes

The course_man.php includes the functions.php with
Language: PHP
include 'includes/functions.php';

then the functions.php includes the config.php it needs to be like this
Language: PHP
include 'includes/config.php';

and not
Language: PHP
include 'config.php';

as one you would imagine.

--

Student Number: 7298-786-3
Re: Assignment 2 - Databse Design
April 15, 2011 08:16PM
@Johnny - 72985186
/*------includes for connection to database-----*/
include('includes/config.php');

hope this helps.
Re: Assignment 2 - Databse Design
April 16, 2011 02:25PM
how do i update the course_student table should I:

first add the student and search for their idno, name, surname, and email to get their sno?

or is there any other way?
avatar Re: Assignment 2 - Databse Design
April 17, 2011 07:28PM
odd.. that's exactly what I did :/ treid to google a solution and found a bunch of complicated methods so thought there was more to it than just include/config.php haha. Will try again. Thanks guys.
avatar
Mac
Re: Assignment 2 - Databse Design
April 18, 2011 07:39AM
xmgcoyi Wrote:
-------------------------------------------------------
> how do i update the course_student table should
> I:
>
> first add the student and search for their idno,
> name, surname, and email to get their sno?
>
> or is there any other way?

You probably meant to ask "insert a new record in the course_student table?"

You can use a function that returns the last generated auto incremented id - in this case the sno.
See http://php.net/manual/en/function.mysql-insert-id.php
Re: Assignment 2 - Databse Design
April 18, 2011 02:19PM
Thanks Mac! Thats exactly what i meant to ask grinning smiley
Re: Assignment 2 - Databse Design
April 18, 2011 05:43PM
Should the function.php file contain ALL your code and then just call the functions in other pages for eg.
Language: PHP
addCourse() deleteStudent() checkField() printError()
avatar Re: Assignment 2 - Databse Design
April 18, 2011 05:51PM
95% of my code is in my functions.php, I prefer having my php code separate from my html - it just looks neater but that's just me smiling smiley

A word to the wise ain't necessary - it's the stupid ones that need the advice.
Student Number:72793775
Re: Assignment 2 - Databse Design
April 18, 2011 06:09PM
Thanks shaun
avatar
Mac
Re: Assignment 2 - Databse Design
April 19, 2011 06:50AM
I do not expect you to make intensive use of functions, although it is good if you do!
Re: Assignment 2 - Databse Design
April 19, 2011 07:44AM
Guys and Mac:
I am thinking of listing the students' important information so that a user can see this information at a glimplse. There would be a link to view a complete student details next to each listing. This link takes the user to page that displays only 1 student's complete information.

Is this the best way or should I list all information in student_man.php?

Oh... In the first solution above I also have a field listing all students' registered course.

Please excuse any ambiguities!
Re: Assignment 2 - Databse Design
April 19, 2011 08:00AM
Last I counted I think I'm using about 30 functions, I actually seperated them into 2 include files, functions.php and form_functions.php
avatar Re: Assignment 2 - Databse Design
April 19, 2011 08:25AM
Haven't used any functions yet and I need to finish by the end of the week! (going on Holiday).

But good to hear that we don't HAVE to use loads. Planning on using them for my validation though. Almost done getting all the basics going, just working on the last bit of my emailer. Struggling a little. I can print a list of all the students names, surnames and email addresses but struggling to get this into a variable to use in the email message! Will try again this afternoon smiling smiley
avatar
Mac
Re: Assignment 2 - Databse Design
April 19, 2011 08:32AM
xmgcoyi Wrote:
-------------------------------------------------------
> Guys and Mac:
> I am thinking of listing the students' important
> information so that a user can see this
> information at a glimplse.

You can, no problem. I do not want to be descriptive, therefore the minimum requirements were given and you can improve as you want.
avatar
Mac
Re: Assignment 2 - Databse Design
April 19, 2011 08:33AM
Stefan.Wiswedel Wrote:
-------------------------------------------------------
> But good to hear that we don't HAVE to use loads

It does not mean you should skimp on it smiling smiley
avatar Re: Assignment 2 - Databse Design
April 19, 2011 09:19AM
Mac: Ya, as I'm a total newb, it started off being much easier to just code seperate PHP files. Kinda had the aim of condensing them into functions at a later stage but time is against me so will see how far I get!
avatar Re: Assignment 2 - Databse Design
April 20, 2011 08:06PM
I'm busy trying to add the delete, edit and add functions into the student table( By the way can we just use html instead of php to generate the table on the page and then use php to just insert the info from the database into the table? or would it be expected to use php for the whole process?)

What I'd like to know is should we strictly keep to the page structure as shown in the tutorial or would it be acceptable if we add a few pages e.g a page to delete students, a page to edit students and a page to add. Also for the add new student part in the student table wouldn't that mean just creating a link that links to the student_reg.php form then the admin can add a new student from there?

Also are there any specific course information provided to us or should we just make up our own courses?

Guess it's going to get a bit mind boggling from here on now haha
avatar Re: Assignment 2 - Databse Design
April 20, 2011 08:21PM
Hi Johnny,

Will answer as best I can.

In terms of doing HTML and PHP it is probably advisable to do the tables etc.. in HTML and then just put the PHP in where necessary.

With the page structure, you are able to add more pages of you like. I think I mentioned before that I have, for example, a course_man.php page. If I click ADD course it takes me to a new php page and then clicking add on that page directs to another php page/script that actually adds the field to the database. This isn't ideal and it would be better to use functions and if/else statements to keep everything neater and cleaner. I just found this the easiest way to do it with my level of PHP knowledge. I am still hoping that in the future I will get time to go back and condense things but I only have a few days left before I go on holiday so I don't see that happening.

Good luck!
avatar Re: Assignment 2 - Databse Design
April 20, 2011 08:33PM
Ah ok cool thanks. Think I will also go about it that way for now. Just to be sure that I meet the deadline and have all the basic requirements completed. I plan to improve on my code if I finish before the due date, such as adding my code to functions etc. which I really haven't used much of haha
avatar Re: Assignment 2 - Databse Design
April 20, 2011 08:38PM
Likewise! confused smiley
Re: Assignment 2 - Databse Design
April 21, 2011 12:49PM
As my project gets bigger i find that i want to use more and more functions for almost every php code. this presents the problem of the functions.php file being all clogged up with all different php code. is there a way to structure my functions.php file so that my code can be easily readable perhaps?smile
avatar Re: Assignment 2 - Databse Design
April 21, 2011 01:04PM
Going to spend the afternoon working on my form validation and hopefully figure out how to use functions to do this. Maybe once I have played with functions a bit I will be keen to use them all over smiling smiley

xmgcoyi: Can you not just comment out some headings and then group your functions to make them easier to find etc??
avatar Re: Assignment 2 - Databse Design
April 21, 2011 01:08PM
Add comments and do like all the functions relating to students together, then courses, then validation etc

A word to the wise ain't necessary - it's the stupid ones that need the advice.
Student Number:72793775
avatar Re: Assignment 2 - Databse Design
April 21, 2011 02:30PM
OK. So getting a little used to functions. Been working on my student_reg form most of the time and have managed to add my php script for adding the student as an include instead of the browser going to a seperate php page.

What I am struggling with is my form validations. I am just trying to start with something simple, check if a field is blank. I manage to do it fine by including my functions.php and then using the function but even if the function fails, the script still runs and adds the student to the database. Any ideas? My function is below and I put it in just after I check if the submit button is checked and just before I check if the DB is there and do all the SQL stuff.
Language: PHP
//Validate e-mail function function blank($email){ if($email ==""){ print "Please enter email."; }   else {   } }
Re: Assignment 2 - Databse Design
April 21, 2011 03:06PM
Depends on how you call the function.

I have a single function that validates the entire form and build up my student object. At the same time it adds any error messages to an error array. After the function has run I check the length of the error array. If empty I continue to add it to the DB, else I show the errors.

Alternatively you can use something like this:

Language: PHP
function validate($value) { if (/* some validation */) { // validation passes return true; } else { // validation fails return false; }   $valid = true;   $valid &= validate($email); $valid &= validate($fname); ... etc   if ($valid) { // Add to db } else { // Something is invalid // Show message }

--

Student Number: 7298-786-3
avatar Re: Assignment 2 - Databse Design
April 21, 2011 03:22PM
Thans wsbraun. I did as you suggested with just checking if the field was blank or not and then just checking one field and it worked perfectly. Now to work out a function to check it all smiling smiley
avatar Re: Assignment 2 - Databse Design
April 21, 2011 05:08PM
I added my validation into my add and edit functions for my students & courses

A word to the wise ain't necessary - it's the stupid ones that need the advice.
Student Number:72793775
Sorry, only registered users may post in this forum.

Click here to login