zafira Posted October 17, 2015 Share Posted October 17, 2015 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. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 17, 2015 Share Posted October 17, 2015 We won't do your homework for you. I you want help, show us your current code and tell us what exactly your problem is. And please choose proper thread titles. Nonsense like “I need help” doesn't tell us anything, because everybody who creates a thread obviously needs help. Quote Link to comment Share on other sites More sharing options...
zafira Posted October 17, 2015 Author Share Posted October 17, 2015 <?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> Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 17, 2015 Share Posted October 17, 2015 (edited) 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 October 17, 2015 by Jacques1 Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted October 17, 2015 Solution Share Posted October 17, 2015 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']]; ?> Quote Link to comment Share on other sites More sharing options...
zafira Posted October 17, 2015 Author Share Posted October 17, 2015 thnks for helping Quote Link to comment Share on other sites More sharing options...
zafira Posted October 17, 2015 Author Share Posted October 17, 2015 thank you for helping, i really appreciate Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.