Welcome! Log In Create A New Profile

Advanced

Task 4A, Task 4B( 1 + 2 ), Task 4C

Posted by vad 
Announcements Last Post
Announcement myUnisa availability 21 to 24 March 2019 03/25/2019 12:25PM
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
vad
Task 4A, Task 4B( 1 + 2 ), Task 4C
February 07, 2010 09:27PM
These tasks are successfully completed.

I had a real challenge trying to set my email DNS server. I made use of the ini_set function instead of setting it up in my php.ini file. I also included an additional parameter, i.e. $headers, hence, I could include the 'from email address'.
Re: Task 4A, Task 4B( 1 + 2 ), Task 4C
March 11, 2010 06:40AM
Questions regarding 4A,B. Does the PHP editor raise warnings if the variable referred to is not on the debugging page?
4A works- when I tick the check boxes it displays on IE,Thankyou.php.
Does a foreach () through an error if no values are sent, is that why we use if $counter==4, to not run the for each loop if empty.
avatar
Mac
Re: Task 4A, Task 4B( 1 + 2 ), Task 4C
March 11, 2010 07:15AM
No warnings - you have to catch it.
The counter is just used to ensure that all 4 fields (in this case) has been completed before the form is processed (in this case a foreach loop is used to process the form data, but it could be anything).
Re: Task 4A, Task 4B( 1 + 2 ), Task 4C
March 11, 2010 08:19AM
thanks Mac then I need to ask if something is wrong with below snippet. It works if I do it through IE and have a value.
If I debug in PHP editor it warns invalid argument supplied foreach()
Quote
php
<?php
$title="thankyou";
include ("header.php"winking smiley;

$postfirstname=$_POST['firstname'];
$postlastname=$_POST['lastname'];
echo "thanks for responding to this survey $postfirstname $postlastname";
echo "<br><br>";
echo "<b> These are your faviorite book categories:</b>";
echo "<br><br>";
$postchoice=$_POST['choice'];

foreach ($postchoice as $echochoice)
{
echo "<p> $echochoice </p>";
}
include ("footer.php"winking smiley;
?>
avatar
Mac
Re: Task 4A, Task 4B( 1 + 2 ), Task 4C
March 11, 2010 08:47AM
This code is 100%. I just supllied the Editor as a freeware option to code in, so I don't know it's ins and outs (I use Dreamweaver) but I suspect the Editor may generate this error because the array is not passed to thankyou.php (when you open thankyou.php, there is no array present because you oppened thnakyou.php on its own, separate from bookform.php).

Try add the code below in the editor before foreach() - you can use it for IE as well.

Language: PHP
if (!empty($_POST['choice'])) foreach ($postchoice as $echochoice)

Better still - use brackets - the non-use of it I discourage:

Language: PHP
if (!empty($_POST['choice'])){ foreach ($postchoice as $echochoice){ echo "<p> $echochoice </p>"; } }
Re: Task 4A, Task 4B( 1 + 2 ), Task 4C
March 11, 2010 10:05AM
Thanks Mac it is also what I suspected.By trying to investigate the differences I used the empty function.
But knowing the code is correct I can atleast move on.
regards
Tny
Re: Task 4A, Task 4B( 1 + 2 ), Task 4C
March 24, 2010 08:49PM
Task 4A-1, Task 4B-1,Task 4B-2 and Task 4C-1 have been completed successfully. For task 4C-1 I received the success message, but don't get a email. From what I understand I wont receive a mail if executing the code on my localhost, because localhost is not directly connected to the internet.
avatar
Mac
Re: Task 4A, Task 4B( 1 + 2 ), Task 4C
March 25, 2010 07:16AM
That is correct. Your localhost server is not connected to the Internet (even though our PC may be), so it cannot send or receive emails. Sending an email with PHP is very simple, and almost always works without much tweaking of the code required.
Anonymous User
Re: Task 4A, Task 4B( 1 + 2 ), Task 4C
April 06, 2010 02:23PM
Hi

only my e-mail is not sending
but all of task 4 is completed
MDC
Re: Task 4A, Task 4B( 1 + 2 ), Task 4C
April 24, 2010 01:15PM
Also, no e-mail, but all else is done and working fine. I'll spend some time with the e-mail issue some time in the future (when I've got more time!).
Re: Task 4A, Task 4B( 1 + 2 ), Task 4C
July 28, 2010 11:03AM
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?
Sorry, only registered users may post in this forum.

Click here to login