Welcome! Log In Create A New Profile

Advanced

Task 4A, 4B, 4C

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 4A, 4B, 4C
July 27, 2010 02:45PM
All Tasks in lesson 4 completed. Very easy. The Prescibe book contains alot of valuable info on the subject
Re: Task 4A, 4B, 4C
July 28, 2010 11:18AM
Hi, guys.

I'm a little stuck on this Task 4B-1. This is my code for thankyou.php, it comes out blank once I've submitted the form on bookform.php :
Language: PHP
  1. <?php
  2. $title = "Thank-you" ;
  3. include ("header.php") ;
  4. $firstname = $_POST[';$firstname';];
  5. $lastname = $_POST[';$lastname';];
  6. $choice = $_POST[';$choice';];
  7. $counter = 0 ;
  8. if (empty ($firstname))
  9. {
  10. echo "Please enter your first name <br>" ;
  11. }
  12. else
  13. {
  14. $counter++ ;
  15. }
  16. if (empty ($lastname))
  17. {
  18. echo "Please enter your last name <br>" ;
  19. }
  20. else
  21. {
  22. $counter++ ;
  23. }
  24. if ($age<5 OR $age>120) ;
  25. {
  26. echo "Please enter your correct age <br>" ;
  27. }
  28. else
  29. {
  30. $counter++ ;
  31. }
  32. if (empty ($choice))
  33. {
  34. echo "Please select the subjects that reflect your reading tastes<br>" ;
  35. }
  36. else
  37. {
  38. $counter++ ;
  39. }
  40. if ($counter =="4")
  41. {
  42. echo "Thanks for responding to this survey $firstname $lastname" ;
  43. echo "<br><br>" ;
  44. echo "<b>These are your favourite book categories:</b>" ;
  45. echo "<br><br>" ;
  46. foreach ($choice as $category) {
  47. echo "$category <br>\n" ;
  48. }
  49. }
  50. include ("footer.php") ;
  51. ?>

Any suggestions?
Re: Task 4A, 4B, 4C
July 28, 2010 12:58PM
have you accounted for the age variable? is it getting sent through, if not your page will still validate as a value is there but will not add to the counter and the rest will not run.
Re: Task 4A, 4B, 4C
July 28, 2010 01:02PM
I've added the age variable, but it still shows up blank. How do I see/test whether it's getting sent through?
Re: Task 4A, 4B, 4C
July 28, 2010 01:27PM
i took the code that you put up and tryed to run it, it first could not read the variables, i took the $ sign out of where you declared the variable $firstname = $_POST['firstname']; , and i also found that you had a semi colon after the if by your age if ($age<5 OR $age>120) ; i took that out and the script ran without problems.
avatar
Mac
Re: Task 4A, 4B, 4C
July 29, 2010 10:03AM
TIP: change the method to GET, and look what is appended in the URL when you submit the forum.
Re: Task 4A, 4B, 4C
July 29, 2010 11:10AM
Truan,

I've removed the relevant $ signs and the colon, still nothing.

Mac,

I've changed the method to GET, nothing shows up the URL when I submit the form, only localhost/StudentPHP/thankyou.php

In bookform.php code changed to
Language: PHP
<form method="get" action="thankyou.php">

and in thankyou.php changed to
Language: PHP
$firstname = $_GET[';firstname';]; $lastname = $_GET[';lastname';]; $age = $_GET[';age';]; $choice = $_GET[';choice';];

and colon removed after
Language: PHP
if ($age<5 OR $age>120)
avatar
Mac
Re: Task 4A, 4B, 4C
July 30, 2010 07:24AM
If you run the code here below, which is very much the same as yours
Language: PHP
<form action="test.php" method="get"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form>     you will get http://localhost/test.php?fname=1&age=1

fname is there to be caught with $_GET, as is age. And their values.
Re: Task 4A, 4B, 4C
July 30, 2010 01:26PM
also have a look at your php.ini file

there is a setting in there that allows you to log any errors you encounter to screen
display_errors = on

Restart apache - this can be a valuable way of trouble shooting.
Re: Task 4A, 4B, 4C
August 03, 2010 08:54PM
sorry to nitpick - but exactly what comes out blank? is the entire page a blank white page or are the variables blank?

if its the whole page - then - well - sorry - can't help...

if it is the variables - try removing them from the quotes and concatenate them to the end of the quoted text - like such:

echo "thanks for responding to this survey " . ($_POST['firstname']) . " " . $_POST['lastname'];

I can't speak for previous versions of PHP - but I've had to rework most of the exampes to get results - especially in lesson 5 which I am now busy with
Re: Task 4A, 4B, 4C
August 03, 2010 08:57PM
All tasks in Lesson 4 complete
Re: Task 4A, 4B, 4C
August 04, 2010 06:12PM
MicheleC - Yep, the entire page is a blank white page.

Mac & Shellshock - Fixed up my php.ini file, this is what I get in my URL: //localhost/StudentPHP/thankyou.php?firstname=Alessio&lastname=&age=32&choice[]=Fiction
Re: Task 4A, 4B, 4C
August 04, 2010 11:53PM
Finally got it working! After much frustration, moody smiley checked my code for the umpteenth time and found the little mistakes!

On to Task $b-2 & beyond!
Re: Task 4A, 4B, 4C
August 05, 2010 12:30AM
All tasks in Lesson 4 done.
Re: Task 4A, 4B, 4C
August 06, 2010 08:44AM
Completed 4A, 4B, 4C. Not a bad task, not too difficult, but i really needed to prescribed booktongue sticking out smiley. Loving the course so far!!
Re: Task 4A, 4B, 4C
August 09, 2010 01:41PM
All tasks done in section 4. Also had a few typo errors but spotted them early and fixed them. Getting a better understanding of PHP and HTML coding and its all getting so much easier for me. Got a lot of pointers from the forum thanks MAC. Off to task 5.

P.S why was the forum down yesterday 07/08/2010? Or was it just on my side?
Re: Task 4A, 4B, 4C
August 10, 2010 12:36PM
Completed task 4A - B and C
I am really enjoying this course.
I also feel that most of the code can be condensed and streamlined further - I like doing that after tasks to see if I could do it better second time round.
Re: Task 4A, 4B, 4C
August 11, 2010 10:48AM
I had finished Task 4A and then I read the Tut which directed me to Chapter 8 of the prescribed book. When I read the chapter I was puzzled! I found that theres a lot I still don't know! like redirecting users to certain URLs and also encoding and decoding URLs.

Anybody else have the same problem?

Could I fail the project because of this?
Re: Task 4A, 4B, 4C
August 16, 2010 07:48PM
I've also finished all these tasks. Wasn't that hard.

I thought HTMLSpecialChars is quite important, i've heard about it, but now i know what it does.

I've also managed to get the email to send successfully after reading around and changing some settings in the php.ini file (Be very carefull when doing this, always make backups beforehand. I did this purely for my own curiosity), like SMTP and sendmail_from. It will differ depending on which service provider you use.

Happy Hunting.
avatar Re: Task 4A, 4B, 4C
August 25, 2010 11:57AM
Ok i'm mad confused! confused smiley

the tut says we must read chapter 8 for task 4b. all of chapter 8 are exercises which build on top of previous coding exercises in the textbook.

does the tut letter only refer to chapter 8 so that we know what chapter to refer to for the project, because the only thing that 4B-1 and chapter 8 share is the if (empty ($firstname)) statement?

Also the solution to task 4b-1 had nothing to do with chapter 8?

Please someone explain.

>>>
The One that owns The Technology rulez the world!
Re: Task 4A, 4B, 4C
August 25, 2010 01:23PM
theSynth i had the same problem!
avatar Re: Task 4A, 4B, 4C
August 25, 2010 01:50PM
Ok,

task 4A, 4B and 4C completed! thumbs up smiley

>>>
The One that owns The Technology rulez the world!
Re: Task 4A, 4B, 4C
August 25, 2010 03:39PM
Done with THESE
Task 4a, task 4B, 4C

thanks to old forum... or should i say old phorumsspinning smiley sticking its tongue out

I successfuly send myself an email from my vodamail account to my gmail account by using nothing but PHP..cool smiley
Re: Task 4A, 4B, 4C
August 25, 2010 03:44PM
Completed tasks 4A, 4B and 4C. Had some issues submitting the form properly but realised I was still applying my ancient ASP learnings and very quickly fixed it. So far having a lot of fun and learning a lot of things I didn't know about PHP...
Re: Task 4A, 4B, 4C
August 31, 2010 02:14PM
I found a really great way of combining html and php - I thought I would share it with all of you.

Language: PHP
<?php   $meat = "Pork"; $vegetable = "Mash Potatoe"; $soup = "Tomatoe";   $page_header = <<<HTML_HEADER <html> <head><title>Menu</title></head> <body bgcolor="#fffed9"> <h1>Dinner</h1> HTML_HEADER;   $page_footer = <<<HTML_FOOTER </body> </html> HTML_FOOTER;   $page_menu = <<<HTML_MENU <ol> <li> <a href="http://www.google.co.za/#hl=en&source=hp&q=Barbecued+Pork&aq=f&aqi=g10&aql=&oq=&gs_rfai=&fp=f1322c37208bb63f">Barbecued $meat</a> <li> Sliced $meat <li> Braised $meat with $vegetable <li> Creamy rich $soup soup with croutons </ol> HTML_MENU;   print $page_header.$page_menu.$page_footer;   ?>

This i feel is especially useful when you have blocks of html.
Hope its useful to you.
Re: Task 4A, 4B, 4C
August 31, 2010 03:32PM
wow it looks cool
Re: Task 4A, 4B, 4C
September 02, 2010 03:23PM
Finished with 4A, 4B, 4C.
This was all pretty straightforward. smiling smiley
Re: Task 4A, 4B, 4C
September 13, 2010 11:24PM
Successfully completed & understood all tasks. Very straight forward. Peter Fortune
Re: Task 4A, 4B, 4C
September 15, 2010 05:56PM
Completed the tasks in this section, had a bit of trouble with task 4A but went on the previous forums and completed the tasks.
Re: Task 4A, 4B, 4C
September 16, 2010 09:56AM
I also finished the tasks 4A to 4C (at last)
Sorry, only registered users may post in this forum.

Click here to login