Welcome! Log In Create A New Profile

Advanced

Topic 4A

Posted by Anonymous User 
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
Anonymous User
Topic 4A
January 16, 2006 08:21AM
This is the thread for problems/comments related to Topic 4A.
Re: Topic 4A
March 23, 2006 10:49PM
I have successfully completed this topic. And the more I work with PHP, the more I like it!
Re: Topic 4A
March 24, 2006 04:21PM
Hello..

Ok, started topic 4A.

4A-1: Works fine.

Except, I get an error here when I debug:

foreach ($choice as $category) {


But it still processed the form OK.

------

Now, 4B-1 (I know there is a thread for 4B but 4A and 4B are linked)

NOW I'm having trouble with the form, and this error is shown:

Warning: Invalid argument supplied for foreach() in c:\foxserv\www\studentphp\thankyou.php on line 46

And unless I find out where I'm making my mistakes, I can't go any futher because 4B-1 etc all work off the PHP files I'm editing.
Re: Topic 4A
March 27, 2006 05:16PM
I am having a similar problem to Alice, but mine doesn't work at all.

I get this error:

Warning: Invalid argument supplied for foreach() in C:\foxserv\www\studentphp\thankyou.php on line 8


My code is:

<?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 favourite book categories:</b>";
echo "<br><br>";
foreach ($choice as $category) {
echo "$category <br>\n";
}
include("footer.php"winking smiley;
?>

What I don't understand is how it knows to print the value? How does $category automatically become associated with the checkbox's value.
Re: Topic 4A
April 03, 2006 04:41PM
Topic completed
avatar
Mac
Re: Topic 4A
April 06, 2006 12:20PM
I don't have the manual with me now - check http://www.evolt.org/these-things-i-know-php-tips for this

foreach ($_GET as $key => $value) //$_POST in the actual example
$$key = $value;
?> to gather

I'll check tomorrow.
Re: Topic 4A
April 06, 2006 05:54PM
I have completed the topic.
avatar
Mac
Re: Topic 4A
April 07, 2006 09:57AM
The manual is sometimes badly written (we didn't write it) for beginners.

Here's the logic - you're getting the invalid argument error despite the fact that your cod eis correct (it's the same in the handbook). That should tell you that the problem perhaps lies with the form.

Copy the following to the top of thankyou.php

print_r($_POST);

This will show you (in an array) what variables arrived at this page. You'll see it is empty Array() (this does not refer to the array in bookform.php - it gives you an array of all variables, even an array of an array smile- passed.

VERY useful - keep it close by.

So, since it's empty, we know the problem lies with the form.

The problem is that <?php ?> tags are missing around choice[] - how can php use choice[] to create an array if php is not involved?

So simply add tags

<?php
echo "<input name='choice[]' type='checkbox' value='Fiction'>Fiction
<br>

<input name='choice[]' type='checkbox' value='Non-fiction'>Non-fiction
<br>

<input name='choice[]' type='checkbox' value='Theater'>Theater
<br>

<input name='choice[]' type='checkbox' value='Computing'>Computing
<br>

<input name='choice[]' type='checkbox' value='Science'>Science
<br>
<br>

<input type='submit'>";
?>


or, if you want like this

<input name=<?php echo "choice[]"; ?> ...
Re: Topic 4A
April 08, 2006 02:13AM
all done. no problems spinning smiley sticking its tongue out

Re: Topic 4A
April 10, 2006 02:51PM
do I need to insert this

foreach ($_GET as $key => $value) //$_POST in the actual example
$$key = $value;
?> to gather

into thankyou.php?
Sorry, you do not have permission to post/reply in this forum.