Welcome! Log In Create A New Profile

Advanced

eye rolling smiley Apply your knowledge 2-1: background color not displaying

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
eye rolling smiley Apply your knowledge 2-1: background color not displaying
July 10, 2008 03:34PM
Hi out there,
the selected color in colorselect.html is not displaying in my browser (Mozilla)??? I can choose a color when displaying colorselct.html in my browser but as a new window opens (color.php)
the color is still white - the address in the address bar appears as follows: http://localhost/exercises/color.php?color=Yellow

I typed the code as indicated on page 18 of the manual:
<?php

switch ($color) {
case "Yellow";
$bgcolor="#FFCC00";
break;
case "Blue";
$bgcolor="#4682B4";
break;
case "Silver";
$bgcolor="#C0C0C0";
break;
case "Beige";
$bgcolor="#FFE4C4";
break;
}
echo "<html>";
echo "<head><title>Selected Background Page</title></head>";
echo "<body bgcolor='$bgcolor'>";
echo "</body>";
echo "</html>";
?>

Also the code for colorselect.html:
<html>
<head></head>
<body>
<form method=GET action='color.php'>
Choose a Web page background color
<br>
<br>
<input name='color' TYPE='radio' VALUE='Yellow'> Yellow
<br>
<input name='color' TYPE='radio' VALUE='Blue'> Blue
<br>
<input name='color' TYPE='radio' VALUE='Silver'> Silver
<br>
<input name='color' TYPE='radio' VALUE='Beige'> Beige
<br>
<br>

<input type='submit'>
</form>
</body>
</html>

Does anybody has a hint where to search for the problem?

Thanks.
Iris
avatar eye rolling smiley Re: Apply your knowledge 2-1: background color not displaying
July 10, 2008 06:44PM
Hi

I'm not doing the course but I stumbled across your post... HINT: How are you assigning a value to the variable $color?

switch ($color) { ??? but $color has not been declared ???

Your missing a $_REQUEST / $_GET here...

    $color = $_GET['color'];

--------------------------------------------------------------
Don't Assume Everything is a Nail Just Because You Have a Really Big Hammer
Anonymous User
eye rolling smiley Re: Apply your knowledge 2-1: background color not displaying
July 12, 2008 01:37PM
Thanks for your hint.
Since I am completely new to PHP I do not know where to put your line of code:
in color.php or colorselect.html.
On the other hand I see a get command in colorselect.html:
form method=GET action='color.php'
Hence I assume your suggested line of code should be placed in color.php, perhaps straight behind the switch ($color) command?

Please let me know.

Thanks
Iris
Anonymous User
eye rolling smiley Re: Re: Apply your knowledge 2-1: background color not displaying
July 13, 2008 04:49PM
Yes Mac, you are right, checking the earlier forums is a good idea.

I found the solution in the forum of sem1 - Topic: 2A, started by: louisesanders.

Everything is fine now.

Regards,
Iris
eye rolling smiley Re: Apply your knowledge 2-1: background color not displaying
July 15, 2008 12:16PM
Hi guys please help with background color I used the script from the masterskill


<?php
switch ($color) {
case "Yellow":
$bgcolor="#FFCC00";
break;
case "Blue":
$bgcolor="4682B4";
break;
case "Silver":
$bgcolor="#C0C0C0";
break;
case "Beige":
$bgcolor= "#FFE4C4";
break;
}
echo "<html>";
echo "<head><title>Selected Background Page</title></head>";
echo "<body bgcolor= '$bgcolor'>";
echo "</body>";
echo "</html>";
?>


And then I tried the one Iris found on S1
still I have a problem please help.

<?php

switch ($_GET['color']) {
case "Yellow":
$bgcolor="#FFCC00";
break;
case "Blue":
$bgcolor="#4682B4";
break;
case "Silver":
$bgcolor="#C0C0C0";
break;
case "Beige":
$bgcolor="#FFE4C4";
break;

}
echo "<html>";
echo "<head><title>Selected Background Page</title></head>";
echo "<body bgcolor='$bgcolor'>";
echo "</body>";
echo "</html>";
?>

Ryan Harris
eye rolling smiley Re: Re: Apply your knowledge 2-1: background color not displaying
August 01, 2008 09:59AM
I have also read through all the discussions on the topic and tried out the solutions just as Ryan and still find the empty page without colour.
I have used the code in the study guide and on the cd and Mac's code in S1 and they all give the same results. Please help.

JB
avatar
Mac
eye rolling smiley Re: Apply your knowledge 2-1: background color not displaying
August 01, 2008 10:39AM
colorselect.html here under

<html>
<head></head>
<body>
<form method=GET action='color.php'>
Choose a Web page background color
<br>
<br>
<input name='color' TYPE='radio' VALUE='Yellow'> Yellow
<br>
<input name='color' TYPE='radio' VALUE='Blue'> Blue
<br>
<input name='color' TYPE='radio' VALUE='Silver'> Silver
<br>
<input name='color' TYPE='radio' VALUE='Beige'> Beige
<br>
<br>

<input type='submit'>
</form>
</body>
</html>


color.php here under


<?php

switch ($_GET['color']) {
case "Yellow":
$bgcolor="#FFCC00";
break;
case "Blue":
$bgcolor="#4682B4";
break;
case "Silver":
$bgcolor="#C0C0C0";
break;
case "Beige":
$bgcolor="#FFE4C4";
break;

}
echo "<html>";
echo "<head><title>Selected Background Page</title></head>";
echo "<body bgcolor='$bgcolor'>";
echo "</body>";
echo "</html>";
?>


This must work, except if you made typo's in which case the page halts, giving you the impression the page is blank while in fact the code is not being parsed anymore. Error reporting is not always on by default.

In previous forums I have referred to @extract. I'm amazed no-one has picked up on it - it's much easier than using $_GET and &_POST.... so you will learn smiling smiley I guess once your finished with the topic, you don't come back. Hmmm, maybe I need to put this is a new topic. BUT using extract() without using prefixes or the parameter EXTR_SKIP is usually a very big security hole, because it allows an external attacker to overwrite every variable
eye rolling smiley Re: Apply your knowledge 2-1: background color not displaying
August 01, 2008 11:23AM
I have copied the exact code provided by Mac and now gets a green screen with the following message disregarding which colour I select:

switch ($_GET['color']) { case "Yellow": $bgcolor="#FFCC00"; break; case "Blue": $bgcolor="#4682B4"; break; case "Silver": $bgcolor="#C0C0C0"; break; case "Beige": $bgcolor="#FFE4C4"; break; } echo ""; echo ""; echo ""; echo ""; echo ""; ?>

Anyone with any further advice? confused smiley

JB
avatar
Mac
eye rolling smiley Re: Apply your knowledge 2-1: background color not displaying
August 01, 2008 11:49AM
That means there is a typo. Your code is not parsed (interpreted).

The <?php ?> tags tells the server to parse your PHP code. If it shows the code (instead of the result, then the code is not parsed)

Looks like you're missing the opening <?php
so the server does not know that this is PHP code and that it must do something with it. It sees you code as plain HTML code, which is then displayed as is on your screen
eye rolling smiley Re: Re: Apply your knowledge 2-1: background color not displaying
August 03, 2008 08:51PM
I also made a typo when I first typed the color.php code.
I inserted an additional > after <body on line 3

...........
1. echo "<html>";
2. echo "<head><title>Selected Background Page</title></head>";
3. echo "<body> bgcolor='$bgcolor'>";
4. echo "</body>";
5. echo "</html>";

When I executed the script I got the following displayed in the browser.

bgcolor='#C0C0C0'>
Sorry, only registered users may post in this forum.

Click here to login