Welcome! Log In Create A New Profile

Advanced

Question regarding the practical

Posted by 77695976gillon 
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
Question regarding the practical
October 18, 2012 08:16AM
Hi All

Sorry for being so scarce. Been busy at the day job and have had bucket loads of freelance work keeping me away from the books.

I have currently completed about 70% of the student registration site but on re reading the tutorial letter it states we are only allowed 4 pages. I have created it in such a way that once a user clicks add,edit or delete that they are directed to a new page that handles the code and gives a message if failed or succeeded.

Would this be permissible for the project?
Re: Question regarding the practical
October 18, 2012 08:17AM
I have done the same, needed some additional pages to get everything working ...
Anonymous User
Re: Question regarding the practical
October 18, 2012 08:21AM
Me aswell for course management for eg. i have a course_man.php page, course_edit.php page, course_del.php, course_del2.php, it helps with giving the
student extra options like prompts.
Re: Question regarding the practical
October 18, 2012 08:22AM
I am not alone smiling smiley I am really hoping that it is alright had to take the week off to complete this and would hate to start from scratch
Re: Question regarding the practical
October 18, 2012 08:24AM
My page structure is similar ... There was a note that additional features are optional too...
Anonymous User
Re: Question regarding the practical
October 18, 2012 08:36AM
Yes those 4 main pages are basically what needs to be displayed as headings on each and every page making navigation easy for the site viewer
avatar Re: Question regarding the practical
October 18, 2012 09:29AM
I've done the same. the tut letter says "Four main pages (with associated forms) are required (you must use the suggested page names):" I doubt this means only those 4 pages,i think those are just the ones we need to display. . . ? ? ?
Re: Question regarding the practical
October 18, 2012 09:45AM
I thought i was the only one with so many pages...i think this way,it makes it easier to know where to find what and its more organised than just having only one page of complicated code...
avatar
Mac
Re: Question regarding the practical
October 18, 2012 10:08AM
Well, if you use if/else statements on one page then you will have fewer pages.... and that actually makes it easier to maintain..
Re: Question regarding the practical
October 18, 2012 10:19AM
Hey Mac, would you prefer use to do HTML block conditionals on fewer pages than multiple pages?
avatar
Mac
Re: Question regarding the practical
October 18, 2012 11:22AM
Why do you want to use conditional blocks (using just the if)? That is normally used when you have plug-in modules of code, then you add an if to the template. If the module is present then the if block is executed (if HTML, to ensure the code/outcome is presented inside HTML that is otherwsie not shown).

Here there is no template, thus:

Language: PHP
if form was submitted //do this and include any required html else //show form and include any required html
Anonymous User
Re: Question regarding the practical
October 18, 2012 11:37AM
Hi Mac, is it really necessary to close a php script each time using mysql_close? I read it's not necessary as it closes automatically but it is good practise doing so, will this affect marks?
just like to know for future reference, will complete this week, next week is touch up week and submission
http://stackoverflow.com/questions/7515023/is-the-mysql-close-necessary
avatar
Mac
Re: Question regarding the practical
October 18, 2012 12:08PM
It is a choice and good practice, but I do not mark to that level because it is a choice. So it is your choice is you want to follow good practice in this instance. I do not use it.
Anonymous User
Re: Question regarding the practical
October 18, 2012 01:37PM
Ok, thing about open source coding is you get so many different views on certain topics and can get a bit confusing.thx
avatar Re: Question regarding the practical
October 19, 2012 11:00PM
regarding all the pages. I re read the tut letter and look watch punched amongstsmile the eyes, on page 12:
"Note that you only have 4 admin pages, therefore all code related to managing the course (MC1 -
> MC2) must fit in course_man.php. It follows that you must make use of if/else or case
to manage how code is handled."
so goodbye process.php . ..
Anonymous User
Re: Question regarding the practical
October 20, 2012 08:12AM
Lol @ Lance, got so far trying to get the portfolio just 2 work, now I hope we dont need 2 go back
and change anything cutting down on fewer pages. Ok the tut letter says that as an "eg."
Mac also mentioned the main skills being tested are insert, extract delete and how we code it is a matter of our logic,
which is different to his, and everyone else.
Esssential functionality, extra marks are given which makes the app better, the way we coded it,
without changing the db structure, it should work is a priority right now, and I feel using more pages
makes the app better, eg. I have a prompt once a course is created, takes you to a page which asks:
would you like to create another course? or course could not be created due to an empty field.
we could do all this on the same page but most of us are just amateurs new to coding, it is too late to redo everything
avatar Re: Question regarding the practical
October 20, 2012 10:40AM
I spent the whole of last night changing everything lol! got rid of all the extra pages lol! well, whats done now is done.
Re: Question regarding the practical
October 21, 2012 11:53AM
In the same situation as Euwen, I am going to try and include a switch statement and start adding extras to the assignment.

One thing for certain, I am learning quite a bit from the assignment which is all ways a good thing smiling smiley
avatar Re: Question regarding the practical
October 21, 2012 12:06PM
The student registration page is killing my brain cells! confused smiley it's like weed, only after its done you'll feel good smoking smiley. . . not that I ever smoked weedtongue sticking out smiley
Re: Question regarding the practical
October 23, 2012 10:10AM
@Lancevjm, what problems are you having?
avatar Re: Question regarding the practical
October 23, 2012 12:33PM
None yet, I think I'm making more work for myself tho, with the validation on the student_reg page, theres just soooooo much to be checked before the form can actually be submitted. . . Actually I do have a problem, I made a function for my checkboxes and radio boxes, but it only works for the radio's. . . I don't know if I'm allowed to post my code here because its for the practical, am I?
avatar Re: Question regarding the practical
October 23, 2012 12:45PM
Let me elaborate a bit. if for instance the "submit" button is clicked, and one of the check boxes were selected, if there was an error or empty field on the form the user is sent back to form to correct the info he inserted in the form. When this is done all the text boxes and radio boxes "remembers" the data or selections the user entered, except the check boxes.
avatar
Mac
Re: Question regarding the practical
October 23, 2012 01:32PM
You can post parts of the code here no problem.

See this post http://stackoverflow.com/questions/2488960/how-to-remember-checkbox-input-in-php-forms
Anonymous User
Re: Question regarding the practical
October 23, 2012 01:46PM
Hi Mac, is javascript unacceptable in all aspects of this course? I am using a line of javascript which is echoed out in my php script, cant seem to find an alternative
with what I need to be achieved
avatar Re: Question regarding the practical
October 23, 2012 02:02PM
Thanks Mac, will try some of those examples.
avatar
Mac
Re: Question regarding the practical
October 23, 2012 02:52PM
> is javascript unacceptable in all aspects of this course? I

You can use it, but not for validation.
Anonymous User
Re: Question regarding the practical
October 23, 2012 04:12PM
Csmileys with beerL

thx Mac
Anonymous User
Re: Question regarding the practical
October 23, 2012 04:29PM
Last question I promise, then I'm signing out...Mac, back to the student reg page again, eye rolling smiley.. for Courses, must there be a submit button for courses chosen, aswell as a submit button
for the rest of the fields or only 1 which submits everything? like in the tutorial> choose your books, (might sound like a silly question, looking for a better method of doing this)
avatar
Mac
Re: Question regarding the practical
October 24, 2012 07:59AM
Just one button
Re: Question regarding the practical
October 24, 2012 07:13PM
Hi, all
Having lots of headaches and was wondering if anyone have an idea why I get this error message when I want to add a course to the database I get this error (I also get it with the edit and delete functions):

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\unisafiles\add.php on line 53
This is the php code in the add.php file

Language: PHP
<?php     $db_handle = mysql_connect("localhost", "root" , "") or die("Could not connect: " . mysql_error()); mysql_select_db(';registration';, $db_handle) or die(mysql_error());   switch ($_GET[';action';]) { case "add": switch ($_GET[';type';]) { case "course": $sql = "INSERT INTO course (course_name) VALUES (';" . $_POST[';course_name';] . "';)"; break; } break; } if (isset($sql) && !empty($sql)) { echo "<!--" . $sql . "-->"; $result = mysql_query($sql) or die("Invalid query: " . mysql_error());   ?>
Re: Question regarding the practical
October 24, 2012 07:17PM
Could be a missing closing brace at the end ... if it is unexpected end of input it's usually a missing semi-colon or closing brace or even a missing paren in a conditional ...
avatar Re: Question regarding the practical
October 24, 2012 08:29PM
yip, theres no closing bracket at the end of your if. it should be:

Language: PHP
if (isset($sql) && !empty($sql)) { echo "<!--" . $sql . "-->"; $result = mysql_query($sql) or die("Invalid query: " . mysql_error()); }
Re: Question regarding the practical
October 25, 2012 08:01AM
Although this is not the cause of the error, you also need to start putting your database connection parameters in an include file as stated in the Tut letter, otherwise it cannot be marked by Mac's system. It is better to do this from the start than having to edit it in afterwards and maybe missing one instance and then having some database actions not working when your portfolio gets marked.
Re: Question regarding the practical
October 25, 2012 08:40AM
Thanks, guys, for the suggestions and comments. Although I know about the configuration page, I have no idea what it is??? Where is it mentioned in the tutorials or handbook?
Anonymous User
Re: Question regarding the practical
October 25, 2012 09:03AM
That script honestly looks complex, I got an instant headache myself, lol.. I used the exact same method to create a course that I used to register a student,
A delete script is really basic if you dont use an if statement

Language: PHP
$id = $_GET[';id';];   $result=mysql_query("DELETE FROM table_name where id=$id");   echo "Deleted!";   ?>
Anonymous User
Re: Question regarding the practical
October 25, 2012 09:09AM
The config file is just a small sript with your database name, and your mysql details which you should
include to your pages instead of re-connecting to mysql each and every time, It also saves alot of time
not just for you, but also when it will be marked. I will be totally honest the tutorial and book only helped
me to an extent with creating this project, internet research and fellow students helped the most, i saw it
as a bad thing at first, but its a good thing. Mac supplied us with a rod, not the fish
Re: Question regarding the practical
October 25, 2012 09:53AM
77686160 Wrote:
-------------------------------------------------------
> Thanks, guys, for the suggestions and comments.
> Although I know about the configuration page, I
> have no idea what it is??? Where is it mentioned
> in the tutorials or handbook?

Look at the tutorial: php13p1.html. They use variables to store the mysql connection parameters. Use that approach and then look at the tutorial php8p9.html that expalins the "include" function. So in the end you keep all your connection details in one file and include that file in all the pages that use the database. So in the end if you need to change the connection details (which Uncle Mac has to do to test your portfolio) then you only have to change the information in the "config.php" file. This is also explained at length in the Tut letter.
Re: Question regarding the practical
October 25, 2012 09:55AM
I have an external file called constants which houses all the db info as well as table names, constants are useful things ... I find this is a better and potentially even a safer approach to setting up db credentials ... And you're totally right about opening one connection through an include file, same approach I had for the portfolio
Re: Question regarding the practical
October 25, 2012 08:14PM
Thanks everyone, this answers my question about the config file too.
Re: Question regarding the practical
October 26, 2012 12:09PM
Hi, Ok one last question: Im trying to validate the date of birth (YYYY-MM-DD)...and im using the following regex
Language: PHP
case ';dob';: $pattern = "/^[\d]{4}-[\d]{2}-[\d]{2}$/";

its still returns an error when i insert eg. 2001-03-22, what am i doing wrong?
avatar Re: Question regarding the practical
October 26, 2012 12:14PM
hey Sandra, I don't even know what that is lol! I converted my dob to an array and then validated it.
Re: Question regarding the practical
October 26, 2012 12:30PM
@Lancevjm...LOL its ok,i only learnt about this "REGEX" stuff a few days ago...hehehe n i thought i should try it out...lol oh well guess im gonna have to learn some more or forget about it for now...
avatar
Mac
Re: Question regarding the practical
October 26, 2012 01:17PM
Ha, regular expressions.

Language: PHP
if (preg_match(';/\\A(?:^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|(1[0-9])|(2[0-3]))\\:([0-5][0-9])((\\s)|(\\:([0-5][0-9])))?))?$)\\z/';, $date)) { // date is valid } else { // date is invalid }

There is an inbuilt checkdate function, and then there is this way, one of may approaches

Language: PHP
<?php   $date_format = ';Y-m-d';; $input = $_POST[';date';]';; // or where ever you get it from   $input = trim($input); $time = strtotime($input);   $is_date_valid = date($date_format, $time) == $input;   print "Valid? ".($is_date_valid ? ';yes'; : ';no';); // this is like using an if/else, just another way   ?>
Re: Question regarding the practical
October 26, 2012 01:27PM
I am having difficulty figuring out the code to delete/update/add courses (or students) in both the course and course_student tables. For example this code delete the course in the course table, but how do I get it to delete in course_students too? Any suggestions?

Language: PHP
<?php $db_handle = mysql_connect("localhost", "root" , "") or die("Could not connect: " . mysql_error()); mysql_select_db(';registration';, $db_handle) or die(mysql_error());   $coursesql="SELECT*FROM course";   $id = $_GET[';cid';];   $result=mysql_query("DELETE FROM course WHERE cid=$id");   echo "Deleted!"; ?>     <p><a href="course.php">Delete another course</a> OR <a href="course_man.php">Back to course list</a></p>
avatar Re: Question regarding the practical
October 26, 2012 01:37PM
Question: So i made this function. "$reg_data" is an array which stores the user input from my forms.

Language: PHP
function sanitise($reg_data){ $count = count($reg_data); for($i = 0; $i < $count; $i++){ $reg_data[$i] = strip_tags($reg_data[$i]); $reg_data[$i] = trim($reg_data[$i]); $reg_data[$i] = mysql_real_escape_string($reg_data[$i]); $reg_data[$i] = htmlspecialchars($reg_data[$i]); $reg_data[$i] = htmlentities($reg_data[$i]); if (get_magic_quotes_gpc()) { $reg_data[$i] = stripslashes($reg_data[$i]); } } return $reg_data; }

To sanitise the user input. When I "echo" the data to check if it worked, it does, but when I insert the data into my db then it doesn't. For instance in my textbox i'll enter "<table align="center">" before a surname. when I echo it, it displays just the surname and no table, when its inserted into my db and i check it on the student_man page it makes a table??? what could be the problem?
Re: Question regarding the practical
October 26, 2012 01:55PM
Thanks Mac...Looks complex though.i'll play around with it untill i get it right.
Re: Question regarding the practical
October 26, 2012 02:02PM
@77686160 , you need another query to delete from the course_student table...using the same $cid eg.
Language: PHP
$result2 = mysql_query ("DELETE FROM course_student where cid = $id");
avatar
Mac
Re: Question regarding the practical
October 26, 2012 02:06PM
77686160 Wrote:
-------------------------------------------------------
> I am having difficulty figuring out the code to
> delete/update/add courses (or students) in both
> the course and course_student tables. For example
> this code delete the course in the course table,
> but how do I get it to delete in course_students
> too? Any suggestions?

When you delete the student, you use his id to find his entries in the course_students table, which will allow you to find the row id, which will allow you to delete the row, as one option, else just delete from row where sno = student id. Rather write out the logic, then add the code to fulfill that logic.
avatar
Mac
Re: Question regarding the practical
October 26, 2012 02:16PM
77726812Lancevjm Wrote:
-------------------------------------------------------
> Question: So i made this function. "$reg_data" is
> an array which stores the user input from my
> forms.

You are confusing me....why do you want to add html code in a text box? Then you say it is not added to the db but then you say it is inserted into the db... I am also not sure where you echo from? That said, htmlentities and specialcharacters is where this probably happens. There is no sense in adding html to your db data - you want to separate presentation (through HTML) and data. Pull pure data into HTML
avatar Re: Question regarding the practical
October 26, 2012 02:32PM
not because I want to, but are we not supposed to prevent our app from attacks? like users who would want to "brake" or hack it by inserting some PHP, HTML or other language syntaxes into the textboxes?
What i was trying to achieve is to prevent those things from happening, so basicly checking all the data entered and making sure its just pure string data.
Sorry, only registered users may post in this forum.

Click here to login