Data and Forms problems

hi I have this project that requires taking data from a html form that has different inputs such as pulldown menu with options and radio menu, each option for the pulldown menu has a value but also has text. my php script takes the option from the html using a name but then when i echo that variable it displays the value, i want to display the text.
heres the code
[php]
// compact if-else statement
$os = (isset($_POST[‘os’])) ? $_POST[‘os’] : “”;
echo “Your operating system is “.$os.”
\n”;
[/php]
this code displays the value. an example would be from above if you select windows7(below-html) from the menu the echo display would be w7, i want it to say the Text that follows the value, so in this instance Windows 7.

 <tr>
             <td class='c1'> Operating System</td>
             <td>
                <select  name="os" id="os">
                    <option  value="0">--select operating system--</option>
                    <option value="w7">Windows 7</option>
                    <option value="w7p">Windows 7 Pro</option>
                    <option value="w8">Windows 8</option>

                </select>
             </td>

i apologize if this is confusing i dont know how else to explain it. Basically when the script is ran i want the display to say Your operating system is Windows 7 not the value=“w7”.

Assuming you have to keep the input like that, you’ll need to either use multiple if-elseif statements or a switch, something like
[php]
switch($_POST[‘os’]) {
case ‘w7’:
echo “Your operating system is Windows 7
\n”;
break;
case ‘w7p’:
echo “Your operating system is Windows 7 Professional
\n”;
break;
case ‘w8’:
echo “Your operating system is Windows 8
\n”;
break;
}[/php]If you want to use the if-elseif statements, then it would be
[php]if($_POST[‘os’] == ‘w7’) {
echo “Your operating system is Windows 7
\n”;
} elseif($_POST[‘os’] == ‘w7p’) {
echo “Your operating system is Windows 7 Professional
\n”;
} elseif($_POST[‘os’] == ‘w8’) {
echo “Your operating system is Windows 8
\n”;
}[/php]
You can’t use $_POST[‘os’] in your echo because its going to be w7, w7p or w8 because that’s what you have in the option value. if you have to use that variable, then you need to change the value to match what you want echoed.

Sponsor our Newsletter | Privacy Policy | Terms of Service