单选按钮在PHP中不起作用

时间:2011-06-14 02:17:50

标签: php

将错误视为

Parse error: parse error in C:\Project1\radio.php on line 12

此代码给出了上述错误

<?PHP
    $male_status = 'unchecked';
    $female_status = 'unchecked';
    $var="Default";
    if (isset($_POST['Submit1'])) 
    {   

        //$var="Got set";

        $selected_radio = $_POST['gender'];

        if ($selected_radio = = 'male') 
        {
            $male_status = 'checked';
        }       
        else if ($selected_radio == 'female') 
            $female_status = 'checked';


    }       

?>
<html>
<head>
<title>Radio Buttons</title>
<script>
 //document.form1.textBox.value="";
</script>

</head>
<body>
<FORM name ="form1" method ="post" action ="radio.php">

<Input type = 'Radio' Name ='gender' value= 'male'
<?PHP print $male_status; ?>
>Male

<Input type = 'Radio' Name ='gender' value= 'female'
<?PHP print $female_status; ?>
>Female

<P>
<Input type = "Submit" Name = "Submit1" VALUE = "Select a Radio Button">
My cal
<Input type = "Text" Name = "textBox" VALUE = "<?php echo $var  ?>">
</FORM>
</body>
</html>

2 个答案:

答案 0 :(得分:3)

你在这里遇到语法错误:

if ($selected_radio = = 'male')
                    ^^^

应为==

答案 1 :(得分:3)

if ($selected_radio = = 'male')更改为if ($selected_radio == 'male')。等号(=)必须在一起(==)。