Selene Rivas' Blog

PHP

Posted in Dailies by aelirri on March 3, 2010

I still need to do some homework, but since I’ve been working all day I thought I’d do something that I enjoy :D

Anyways, today I learned about several PHP loops (most of which I already knew), and my program focuses on a loop I did not know before, the switch-case loop. It is basically like an if-else loop, only that it is easier to write. Personally, I like it!

HTML:

<html>
<body>
<form action=”scariestCreature.php” method=”post”>
What is the scariest fantastical creature? (eg. Werewolf) <br />
<input type=”text” name=”creature” /> <br />
<input type=”submit” value=”Send” />
</form>
</body>
</html>

<html> <body> <form action=”scariestCreature.php” method=”post”> What is the scariest fantastical creature? (eg. Werewolf) <br /> <input type=”text” name=”creature” /> <br /> <input type=”submit” value=”Send” /> </form> </body></html>

PHP:

<?php

$creature = $_POST['creature'];

switch($creature){

case ‘werewolf’:

echo ‘Make sure to stock on the silver bullets!’;

break;

case ‘zombie’:

echo ‘Melee weapons never run out of bullets!’;

break;

case ‘vampire’:

echo ‘For honest-to-god Vampires, just use sun.’;

break;

case ‘killer bunny’:

echo ‘Holy Hand Granade!’;

break;

default:

echo ‘I\’m sure it is nothing to be afraid of!’;

}

?>

I still don’t know how to make it possible for the code to actually work :( If someone knows, please tell me.

****

On an unrelated note, you have to listen to this song:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.