Welcome! Log In Create A New Profile

Advanced

Task 5A, 5B, 5C

Posted by Truan Frames 
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
Task 5A, 5B, 5C
August 03, 2010 01:58PM
Finished all tasks in chapter 5

Tasks A and B were not to difficult spinning smiley sticking its tongue out but had to delve into the past years forums to get C workinghot smiley.
Re: Task 5A, 5B, 5C
August 05, 2010 11:49AM
Task 5A-1: I get the choice to display, but not firstname lastname.

How do I declare the variables?

In hiddenfields2.php I've tried:
Language: PHP
$fname = $_POST[';firstname';]; $lname = $_POST[';lastname';];
and
Language: PHP
$fname = $_POST[';fname';]; $lname = $_POST[';lname';];
and nearly every other combination, but not working.

Any suggestions as to what I'm missing, or where I could be going wrong?
avatar
Mac
Re: Task 5A, 5B, 5C
August 05, 2010 12:59PM
It can only be ['fname'] if you used the example in the manual, because there the name of the text field is fname.You can name the variable anything you want e.g. $first_name_passed=$_POST['fname']; but keep it the same to ease fixing code.

Do some error checking - change the form method to GET, and see what is appended in the URL in your browser after hiddenfields2.php (e.g. ?fname=xxx&lname=yyy)

Then you know exactly if and what is passed or not, and then you will know on which page to concentrate for fixing.
Re: Task 5A, 5B, 5C
August 05, 2010 01:11PM
Mac,

Thanks. I changed the form method to get, this is what's appended to my URL: ?choice[]=Science&fname=&lname= , seems fname & lname are not getting passed.
Re: Task 5A, 5B, 5C
August 05, 2010 01:23PM
Got it, Mac.

Thank you.
Re: Task 5A, 5B, 5C
August 11, 2010 06:02PM
Task 5A done, a bit stuck on 5B - posted my problem in "Lesson 5 - I don't get the cookies" thread, and 5C done with *PLENTY* help from the past years' forums!
Re: Task 5A, 5B, 5C
August 15, 2010 11:39AM
Ag no I feel so stupid lol. Have just finished 5A and kept on getting the error on form 3 Undefined index. I went back into a lot of history on the forms and all my coding was perfect but still got that error.
Guess what was the problem? At the beginning where you put this code

<form method='post' action='hiddenfields2.php'>, there was my problem. I put method='post' in the ''. As soon as I took it away it was all good. So my code looks like this:

<form method=post action='hiddenfields2.php'>. Damn typo error.

Well off to 5B Cookies
Re: Task 5A, 5B, 5C
August 15, 2010 12:08PM
Have just finished Task 5B. Found a piece of code in last years forum that helped me finish the Cookie coding but have no idea what it all means. Mac can you please explain to me?
The coding is:

isset ($_COOKIE['background']) ? $background = ($_COOKIE['background']) : $background="";

If anybody needs help with Task 5B i'm all ears. Except with this statement but you can follow how Mac explains.
Off to task 5C Sessions
avatar
Mac
Re: Task 5A, 5B, 5C
August 15, 2010 01:35PM
Note to be careful of copying code.... retype the part method='post' and the problem will go away. ' is not the same as `

This
Language: PHP
isset ($_COOKIE[';background';]) ? $background = ($_COOKIE[';background';]) : $background="";
is a shortcut way of writing
Language: PHP
if(issset ($_COOKIE[';background';]) ){ //do this ... the ? part here above i.e. $background = ($_COOKIE[';background';]); // that is, use the colour } else{ //do this .... the : part here i.e. $background=""; //that is, $background should be empty   }
Re: Task 5A, 5B, 5C
August 19, 2010 06:23PM
Just finished with 5C. Work for me this week was hectic so only got time to finish now. Had no problem finishing it.

Cheers all I'm off to bed

zzzzzzzzz
Re: Task 5A, 5B, 5C
August 24, 2010 04:43PM
Finnaly Completed the whole of lesson 5, I was far to careless and had a bunch of typo'smoody smiley. Took me an age to find and fix them allsmile.
avatar Re: Task 5A, 5B, 5C
August 25, 2010 06:38PM
task 5A done. Bring it on topic 5!!! grinning smiley

>>>
The One that owns The Technology rulez the world!
avatar Re: Task 5A, 5B, 5C
August 26, 2010 03:58PM
Just completed task 5b.

Like all my other exercises i read the manual and then the text book before attempting the task.

I decided to reference from the book instead of finding the answer from the forums - just to do something different. Found the $_COOKIE solution on page 51 of the textbook, instead of page 370 which just introduces the topic like the manual. I found this useful, to also practice searching the book. Searching the forums is good - please don't get me wrong - but searching the textbook is also a skill. thumbs up smiley

>>>
The One that owns The Technology rulez the world!
avatar
Mac
Re: Task 5A, 5B, 5C
August 27, 2010 06:59AM
Yip, we cannot give all the pages - depending on what your problem is, the solution could be anywhere in the book - even in sections where it is not specifically covered!
avatar Re: Task 5A, 5B, 5C
August 27, 2010 11:41AM
Just completed task 5C. Found Task 5C to be more challenging than the others - had to search the forums...check out 2009 forums.

There's something that's still bugging me and it bugged me in task 3b-2...

here's some code from task 5C....

Language: PHP
if (empty ($_SESSION[';bgcolor';])) { $_SESSION[';bgcolor';] = "white"; }

This code runs the first time the script runs (before a color is chosen).

Am I right in saying that we use $_SESSION['bgcolor'] in the "if statement" because we have to declare the bgcolor variable before we can use it in an "if statement", the first time round?
confused smiley

>>>
The One that owns The Technology rulez the world!
avatar
Mac
Re: Task 5A, 5B, 5C
August 27, 2010 05:19PM
Look at what you are saying here.... if the bgcolor is empty (that is, it has not been defined) then give it a default colour of white. This is useful for the reason explained in my previous post here above, since depending on your configuration of the server and PHP on that server, it may generate errors. These warnings about errors do not prevent your code from working in most instances, but generates a "warning" that you should always "test" if a variable exists (to prevent hackers from mis-using you code), and if it does not, then do something about it.

Your code will work the first time - if there is no bgcolor passed to the page, then it is set to white. The second time you run the code, the bgcolor is set in the session, so the if here is not empty, therefore the code in die brackets is not run. Which means you have to add an else statement to cover for this.
Re: Task 5A, 5B, 5C
September 06, 2010 10:19AM
I have completed this entire Task.
Thank you it was interesting working with sessions.
Re: Task 5A, 5B, 5C
September 09, 2010 04:20PM
Finished all these tasks.

Seemed tricky at first, but once i consulted the textbook, and some of the old phorums, it made a lot more sense. Pretty cool stuff.
Re: Task 5A, 5B, 5C
September 13, 2010 09:08AM
Hi done with Task 5A, 5B, 5C, Had a bit of trouble getting the Cookies to work but wrote a silly code to test is it isset or !isset, lol,

$var1 = $_COOKIE['background'];
if (!isset($_COOKIE['background'])) {
echo "error";
}
echo $var1;
Re: Task 5A, 5B, 5C
September 15, 2010 07:08AM
Finished all tasks in these tasks!
Re: Task 5A, 5B, 5C
September 21, 2010 02:55PM
Completed all tasks.
Peter Fortune
Re: Task 5A, 5B, 5C
September 22, 2010 03:22PM
Completed tasks 5A and 5B, battled with the cookies and after going through my code, finally noticed the mistakes I made. Now moving on to Task 5C.
Re: Task 5A, 5B, 5C
September 23, 2010 02:13PM
Completed 5A to 5C....5C was slighly more challenging, but 2009 forums really helped
Re: Task 5A, 5B, 5C
September 25, 2010 09:20PM
Also completed Task 5A and 5B.
Re: Task 5A, 5B, 5C
October 02, 2010 06:41PM
Completed task 5C.
Re: Task 5A, 5B, 5C
October 03, 2010 07:57AM
Also completed 5C, finally, moving to databases.
Re: Task 5A, 5B, 5C
October 10, 2010 04:21PM
Finnish 5A-C got a lot of help from youtube smiling smiley
Sorry, only registered users may post in this forum.

Click here to login