Jump to content

Recommended Posts

I was wondering if someone can show me how to use switch case instead of if for the code below.

 

Here is the original task

 

Create a form that asks a user to select a destination from a list of radio buttons. The choices are: San Francisco, New York, London, Paris, Honolulu, and Tokyo.

 

Write a PHP script that uses a switch statement to evaluate each of the cities, and based on the city selected by the user, sends back a message such as, "Welcome to San Francisco. Be sure to bring your heart and a jacket!" or "Bonjour, let's take a stroll on the left bank!".

 

The code below works, but i don't know how to write it using switch case.

 

Thanks,

 

Hien

 

 

<html>

<head>

<?php

 

if (isset($_POST['method'])) {

$selected_city = $_POST['info'];

print $selected_city;

}

?>

 

<title>Where are you heading to?</title>

 

</head>

<body>

 

 

<br>

<form name="form1" method="post" action="ques9.php">

<p>

<label>

<input type="radio" name="info" value="Expect breezy weather!" >

San Francisco</label>

<br>

<label>

<input type="radio" name="info" value="Remember to go see the Statue of Liberty!">

New York</label>

<br>

<label>

<input type="radio" name="info" value="If you get a chance, say hi to the Queen Mother!">

London</label>

<br>

<label>

<input type="radio" name="info" value="Bonjour, please see the Effiel Towel!">

Paris</label>

<br>

<label>

<input type="radio" name="info" value="Let's hit the beach!">

Honolulu</label>

<br>

<label<input type="radio" name="info" value="How about some sake and sushi later?">

Tokyo</label>

<br>

</p>

<input type="submit" name="method" value="Destination"/>

</form>

 

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/156589-radio-button-with-switch-case/
Share on other sites

You shouldn't ask people to write stuff for you. Read rule #7 - http://www.phpfreaks.com/page/forum-rules

 

But a switch works like this:

switch ($_POST['method']) {
     case 'London':
          echo 'something';
          break;
     // more cases here
     default:
          echo '';
}

Why don't you go fuck yourself your nolife computer geek, I did not you to write my code for me. I just need a hint how the alternative works. Didn't you asshole every need help when first learning programming.

 

I don't need a lecture from a moron who split his time between jerking off and his computer.

 

Don't be an ass

I was wondering if someone can show me how to use switch case instead of if for the code below.

 

Here is the original task

 

Create a form that asks a user to select a destination from a list of radio buttons. The choices are: San Francisco, New York, London, Paris, Honolulu, and Tokyo.

 

Write a PHP script that uses a switch statement to evaluate each of the cities, and based on the city selected by the user, sends back a message such as, "Welcome to San Francisco. Be sure to bring your heart and a jacket!" or "Bonjour, let's take a stroll on the left bank!".

 

Calm down there buddy

 

You saying "can you show me how to..." and then listing the original task as if you copy/pasted it from a assignment looks mighty suspicious if you ask me. And yes I needed help when I first started, but I learned to read the manual and google'd examples then tried it myself.

 

Also, I find it highly ironic that you said:

Don't be an ass

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.