2011-06-14 60 views
-3

它給人錯誤的單選按鈕沒有在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> 
+3

endra你是什麼意思的「不工作」?也可以用例如'<?php echo $ var?>'替換'<?php $ var?>'。 – Tadeck 2011-06-14 02:21:45

+0

是的,它的工作。但我的問題是不同的。錯誤地我已經上傳了這一個。 – Gnan 2011-06-14 02:25:26

+1

*什麼*(不)工作? – deceze 2011-06-14 02:27:31

回答

3

你一個語法錯誤的位置:

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

應該是==

+0

哦.... thanku @deceze。 – Gnan 2011-06-14 02:39:35

3

變化if ($selected_radio = = 'male')變爲if ($selected_radio == 'male')。等號(=)符號必須在一起(==)。

+0

Thanku @Francois Deschenes – Gnan 2011-06-14 02:39:57