Welcome! Log In Create A New Profile

Advanced

Topic 2B

Posted by Dorac 
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
Topic 2B
July 09, 2008 10:58PM
Topic 2B
Anonymous User
Re: Topic 2B
July 10, 2008 03:19PM
Task 2B-1

Problem:
my browser displays the following (array.php) after selecting a book (book.html)

^ The author of is .


I checked both files but I cannot find the error. Does anybody has an idea?
Let me provide you with the code:

array.php

<html>
<head><title>Who wrote that book?</title></head>
<body>
<!--INSERT CODE HERE-->^
<?php
$books["Romeo and Juliet"] = "William Shakespeare";
$books["Exobiology: An Introduction"] = "Jonathan Drake";
$books["War and Peace"] = "Leo Tolstoy";
$books["Portrait of the Artist"] = "James Joyce";
$books["The Lion, The Witch, and the Wardrobe"] = "CS Lewis";
$author = $books[$SelectedBook];
echo "The author of $SelectedBook is $author.";
?>
</body>
</html>

To be on the safe side, for book.html:
<html>
<head><title>Who wrote that book?</title></head>
<body>
<form method='POST' action='array.php'>
Select a book to find out its author:<br><br>
<select name="SelectedBook" multiple size=5>

<option>Romeo and Juliet
<option>Exobiology: An Introduction
<option selected>War and Peace
<option>Portrait of the Artist
<option>The Lion, The Witch, and the Wardrobe
</SELECT>

<br>
<br>
<input type='submit' value='Submit'>

</form>
</body>
</html>

Can anybody help?

Thanks & regards
Iris
Re: Topic 2B
July 10, 2008 08:48PM
Iris,
So that you can understand i am going to explain this in simple terms - not to offend - but as the tutorial obviously does not take this into account:

you issue heres(and with the color selct page) is globals
Older versions of php had register globals enabled by default, newer ones do not
to explain the above
register globals on would take a look at the get string (file.php?option=x&option2=y) or form post variables and automatically assign them with values as variables,
so $option would automatically = x and $option2 would = y

with the newer versions of php register globals is off - safer route, but means you need to assign your variables, looking at the code of array.php

you are calling the variable $SelectedBook but with register globals being off, it is empty
to fix this you need to make sure to assign it a value,
now if you are using a form with the post method, it is best to use the following ammendment to your code:

array.php

<html>
<head><title>Who wrote that book?</title></head>
<body>
<!--INSERT CODE HERE-->^
<?php
//assign $SelectedBook a value
$SelectedBook = $_POST['SelectedBook'];

$books["Romeo and Juliet"] = "William Shakespeare";

...

Also -> completed

Craig G Smith
http://www.joomla-host.co.za
Anonymous User
Re: Topic 2B
July 14, 2008 06:25PM
Hi Craig,
thanks for your support - it works, just the ^ in front of the line is still there, I was not sure what you meant by "Also -> completed.

Anyhow, I remember you mentioned in another thread that you are going to an area without any Internet access. Would you like to tell me where? By the way, are you living in South Africa?

Yeah, I am living in Germany, southern part in the city of Munich.

Greetings to you
Iris
Re: Topic 2B
July 15, 2008 12:42PM
<!--INSERT CODE HERE-->^

Hi
Check your code, next to <!INSERT CODE HERE--> ^ Just a typing error.

Irene
Anonymous User
Re: Topic 2B
July 15, 2008 03:55PM
Hi Irene,
of course, you are right, a typing error, like usual.
Thanks
Iris
Re: Topic 2B
July 19, 2008 05:07PM
Hi

Completed Topic 2B with no problems.

Gareth van Zyl
Anonymous User
Re: Topic 2B
July 20, 2008 01:02PM
Topic 2B done.

Mamog
spinning smiley sticking its tongue out Re: Topic 2B
July 23, 2008 02:12PM
spinning smiley sticking its tongue outHi guys

I am having fun , I done with Topic 2B the forum really works


Thanks

Ryan Harris
Anonymous User
Topic 2B
July 30, 2008 03:03PM
2B is done, it is a bit irritating when you know that you are missing code from the php and you have to sift through the forms to find 1 line angry smiley
Re: Topic 2B
August 01, 2008 03:37PM
2B done. I agree with DavidH. If it wasn't for the forum how would one know what's right and what not? yawning smiley
avatar
Mac
Re: Topic 2B
August 04, 2008 07:01AM
Well, you'd better get used to forums, because you're going to spent more time going through forums than actual coding! If the handbook and manual is used together as intended, then the progression from manual (PHP4 code) to the handbook (PHP5 code) should be pretty clear!
Re: Topic 2B
August 11, 2008 11:46PM
Hi All.

Completed TOPIC 2B.

Forum does help and I often consult them on a day to day basis...

Regards

Justin Leaf-Wright

hot smiley
Re: Topic 2B
August 19, 2008 05:09PM
I've done this exercise

my problem was setting the variable

$SelectedBook = $_POST['SelectedBook'];

I guess I'm getting an idea of how the form page of html passes variables with
the php page;

Sharp!
Re: Topic 2B
August 24, 2008 08:52PM
Thank you for all the positive contibutions from the participants. That helped me a lot in understanding the problem in this task. I have finished mine too, thanks especially to Iris and Craig Smith.

Johan B
avatar
Mac
Re: Topic 2B
August 25, 2008 06:45AM
passing variables from page to page is discussed in the handbook - i get the impression not to many people have bought the handbook? You should get it if you are serious about php!
Re: Topic 2B
October 01, 2008 09:35PM
completed thanks to the forum!
Sorry, only registered users may post in this forum.

Click here to login