Welcome! Log In Create A New Profile

Advanced

4A

Posted by Ordo 
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 4A
July 29, 2009 09:04PM
Done with 4A

Interesting to see arrays passed between pages in a similar way as normal variables. I would have thought that the following would be correct:

Language: PHP
$choice = $_POST['choice[]']; // Not correct!

OR

Language: PHP
$choice[] = $_POST['choice[]']; // Not correct!

but NO, it should be:

Language: PHP
$choice = $_POST['choice']; // This works!

Seems a bit strange. confused smiley
Re: 4A
July 29, 2009 10:20PM
Also done!

I also could not figure that one out immediately, but then I realised that in theory we're only receiving the output of the array and not the actual array itself (correct me if im wrong)

For the fun of it i played around with the concept of using the for() to manipulate a dropdown box giving me options from 1 - 1000. Its great to see that you can actually get your forms to work for you. As web developers we know how time constraining it can be to be given a variety of content fields which needs info and having to do it manually. With PHP it can be 1,2,3 depending you get the logic on how to get your code to work
Re: 4A
August 02, 2009 07:33PM
4A complete
Re: 4A
August 08, 2009 07:39AM
i am catching up started lesson 4 .....

smoking smiley When all else fails , read instructions grinning smiley
smiling smiley Reading is a course on it's own ! smiling smiley
Re: 4A
August 08, 2009 12:20PM
Yup, Thats 4A Done !!!

smoking smiley When all else fails , read instructions grinning smiley
smiling smiley Reading is a course on it's own ! smiling smiley
Re: 4A
August 11, 2009 03:58PM
Form lie at the very heart of working with PHP, you use forms for logging in to restricted pages, registering new users, placing orders with online stores, entering and
updating information in a database,sending feedback...
The name attribute of each form element is used as the array key, making it easy to retrieve the content.
Each and every content is used as the array values

Example
$_POST [ ' name ' ] = $name ;
$_POST [ ' email ' ] = $email ;
$_POST [ ' comments ' ] = $comments ;
avatar Re: 4A
August 12, 2009 12:25PM
This one was much easier than 3B.

Worked first time smiling smiley

Chris
~~~~
"Cleverly disguised as a responsible adult."
Anonymous User
Re: 4A
August 17, 2009 10:22AM
Done with 4A.
Re: 4A
August 19, 2009 11:35AM
Done with 4A on to the next one.
Re: 4A
August 20, 2009 06:58AM
Done 4b-1, 4b2, and 4c-1
Re: 4A
August 20, 2009 09:43AM
Completed 4A,B and C
avatar Re: 4A
August 23, 2009 02:28PM
4A done
Re: 4A
August 24, 2009 11:40AM
Does not work when I complete the form, will try Ordo's hint. My computer at work was updated on Thursday and I have to re-install XAMPP.
fcb
Re: 4A
August 26, 2009 12:25PM
Done.

I replaced the code for the selection boxes with php.

<?php
$bookcats = array('Fiction', 'Non-Fiction', 'Theatre', 'Computing', 'Science');
sort($bookcats); //optional - sorts the categories alphabetically
foreach ($bookcats as $b) {
echo '<input name="choice[]" type="checkbox" value="'.$b.'">'.$b.'<br>';
}
?>

This allows you to ad/remove book categories easily.
Re: 4A
August 30, 2009 05:23PM
Done with 4A
Re: 4A
September 02, 2009 11:50AM
Please help. This is my code for thankyou.php:
<?php
$title = "Thank-you";
include("header.php"winking smiley;
echo "Thanks for responding to this survey $firstname $lastname.";
echo "<br><br>";
echo "<b>These are your favorite book categories:</b>";
echo "<br><br>";
foreach ($choice as $catergory){

echo "$category <br>\n";
}
include("footer.php"winking smiley;
?>
I get the follwing error:
Warning: Invalid argument supplied for foreach() in C:\Program Files\xampp\htdocs\StudentPHP\thankyou.php on line 9
fcb
Re: 4A
September 02, 2009 12:11PM
You must retrieve the POST variables.
The
Language: PHP
$choice
array does not exist,

Add the following after the include() statement:

Language: PHP
$choice = $_POST['choice']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname'];
avatar
Mac
Re: 4A
September 02, 2009 12:16PM
Well, the answer lies in the 1st message here above. You are to first catch the variables on the thankyou page, as explained in messages 1 and 6 and in the previous topics. You did not....!
Therefore, since you did not catch them, the argument is invalid since $choice does not exist.

I also notice a typo in the foreach statement. Now I'm not posting the complete code here, since then you won't be learning smiling smiley
Re: 4A
September 02, 2009 12:45PM
Thanks for help. All done with 4a-1.
avatar Re: 4A
September 15, 2009 01:30PM
Ok ... this really helps... I can say I'm done... but would like to go over it again.....
avatar Re: 4A
September 18, 2009 12:49PM
DONE with A1 interesting to learn how to pass the array to the next page.....
Anonymous User
Re: 4A
September 20, 2009 12:49PM
Done with 4A.
Re: 4A
September 22, 2009 02:45PM
Done
Re: 4A
October 02, 2009 03:47PM
Done with 4A,B and C
Sorry, only registered users may post in this forum.

Click here to login