Jump to content

can anybody help me!


zafira
Go to solution Solved by Barand,

Recommended Posts

Let the user select a language in a pull-down menu. After the user has selected a language and clicked a button, a message should appear with a “Welcome” greeting in that same language. Include at least four different language options.

Link to comment
Share on other sites

<?php

 

 

// Read the selected language.

$language = ($_REQUEST['language']);

 

// make the language array.

$language=array(1=>'Malay','English','Chiness','India');

 

// make the language pull-down menu.

echo'<select name="language">';

foreach($language as $key =>$value) {

echo"<option value=\"$key\">$value</option>\n";

}

echo '</select>';

// Validate the gender.

if (isset($_REQUEST['language'])) {

$language = ($_REQUEST['language']);

 

if ($language == 'Malay') {

$message = '<P><b>Good day, Sir!</b></p>';

 

} else ($language == 'English') {

$message = '<P><b>Good day, Madam!</b></p>';

 

} else ($language == 'Chiness') {

$message = '<P><b>Good day, Madam!</b></p>';

 

} elseif ($language == 'India') {

$message = '<P><b>Good day, Madam!</b></p>';

 

} else { // Unacceptable value.

$message = NULL;

echo '<p><font color="red">You forgot to enter your name!</font></p>';

}

 

}else { //$_REQUEST['gender'] is not set.

$language = NULL;

echo '<p><font color="red">You forgot to enter your name!</font></p>';

}

 

?>

<form action="choose.php" method="post">

 

<br/>

<input type="submit" value="GO!"/>

 

 

</form>

 

</body>

</html>

Link to comment
Share on other sites

You still haven't told us your problem, but the two “else” after the “if” must be “elseif”, and the select element must be within the form, and you need to use $value as the option value, not $key (the key is the numeric array key: 1, 2, 3, 4).

Edited by Jacques1
Link to comment
Share on other sites

  • Solution

It's a lot easier to use an array for the messages

 

form

<select name='language'>
    <option value='1'>English</option>
    <option value='2'>French</option>
    <option value='3'>German</option>
    <option value='4'>Klingon</option>
</select>

processing

<?php
$translations = array (
                    1 => 'Welcome',
                    2 => 'Bienvenue',
                    3 => 'Herzlich Willkommen',
                    4 => 'yI\'el'
                );
echo $translations[$_GET['language']];
?>
Link to comment
Share on other sites

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.