adding a radio button in a php form

here is the html:

 Long   
 Short   
 Closed Trade   

here is the php:

if ($_POST[“longshort”] == “Long”)
{
$buy = “bought”;
} else {
$buy = “shorted”;
} else {
$buy = “closed trade”;
}

I’m getting this error:

Parse error: syntax error, unexpected T_ELSE in /var/www/vhosts/stockaviator.com/httpdocs/wp-content/themes/kleo/kleo/testing.php on line 60

HELP!!! thanks!

Sorry for piecing together this message for I’m a little scattered brain today. ;D )

Quick fix:
[php]if ( $_POST[‘longshort’ == ‘Long’ ) {
$buy = “bought”;
} elseif ( $_POST[‘longshort’ == ‘Short’ ) {
$buy = “shorted”;
} elseif ( $_POST[‘longshort’ == ‘Closed Trade’ ) {
$buy = “closed trade”;
}[/php]

If you are going to be using a lot of radio buttons you might want to checkout the switch statement : http://php.net/manual/en/control-structures.switch.php

If you have any other problems then maybe post the whole form HTML?

the form is above.

thanks for the reply, Striker64. That worked great but was missing the ] :

if ( $_POST[‘longshort’]

Thanks for your help!

Sponsor our Newsletter | Privacy Policy | Terms of Service