954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problems with htmlentities(noob question)

Hey, htmlentities doesn't work in this code of mine, someone know why?
Check line 11-14
Thanks.

<html>
<head>
<title> Welcome <?php echo $_GET['name']; ?> </title>
</head>
<body bgcolor="<?php echo $_GET["favcolor"]; ?>"?

<h1> Welcome <?php echo $_GET['name']; ?> </h1> 

<?php 

foreach ($_GET as $key => $verdi) {
$verdi = htmlentities($verdi);
$key = htmlentities($key);
}
echo "You live in ";
echo $_GET['country'];
echo ", ";
echo $_GET['city'];
echo " And your favorite color is "; 
switch ( $_GET['favcolor'] ) {

case "#ff0000";
$favcolortext="Red";
break;

case "#8bcdff";
$favcolortext="Blue";
break;


case "#fff600";
$favcolortext="Yellow";
break;

case "#0cff00";
$favcolortext="Green";
break;

case "#a200ff";
$favcolortext="Purple";
break;

case "#6000ff";
$favcolortext="Violet";
break;

case "#ff68e1";
$favcolortext="Pink";
break;

case "#fbfadd";
$favcolortext="Vanillia";
break;

case "#730404";
$favcolortext="Dark Red";
break;

case "#10057a";
$favcolortext="Dark Blue";
break;

case "#157a05";
$favcolortext="Dark Green";
break;

case "#17bb9e";
$favcolortext="Cyan";
break;

case "#40f0fb";
$favcolortext="Baby Blue";
break;

}

echo "$favcolortext.";

?>
</body>
</html>


Anyone wants to add me to msn? [email]mzm_mc@hotmail.com[/email]
good coder or not, IDC. Just need some coding buddies =)

Muazam
Light Poster
29 posts since Sep 2009
Reputation Points: 10
Solved Threads: 1
 

You are just setting the value to a variable.

You should do something like this:

foreach( $_GET as $key => $val ) {
  $_GET[$key] = htmlentities( $val );
}
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

Thanks alot, it helped.
Could you explain me one more thing, my books is telling me to do it like this:

foreach ($_GET as $key => $val) {
$val = htmlentities($val);
if ( $key <> "name")

And it says " So on..." the books doesn't tell me more about this.
My question is what is this "<>" function called and what does it do?
or what should I search on google to get more info about this.

Thanks.

Muazam
Light Poster
29 posts since Sep 2009
Reputation Points: 10
Solved Threads: 1
 
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

Thanks, solved.

Muazam
Light Poster
29 posts since Sep 2009
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You