2013-04-26 48 views
0

我需要解決這個問題,我有兩個不同的session variables,我想通過session variable if和else條件回聲消息和單選按鈕名稱大小值?如果和其他條件不工作會話變量?

問題是,當我選擇單選按鈕時,應該顯示size values而不是accessories

比如我需要一個這樣

如果輸入值喜歡的任何號碼

echo "Accessories"; // It Should Be Display Accessories If 
         Any Kind Of Numbers Enter. 

否則如果無線電選擇

echo size name // display size whatever choose 
        from radio button. 

這裏是我的代碼:

<?php 
session_start(); 
if(isset($_REQUEST['test'])) 
{ 
$_SESSION['size1']=$_POST['size']; 
$new_sizes=$_SESSION['size1']; 
$_SESSION['cid1']=$_POST['cid']; 

if(isset($_SESSION['cid1']))  
{ 
echo "Accessories"; 
} 

else 
{ 
echo $new_sizes; 
} 
} 
?> 

<form method="post"> 
<input type="text" name="cid"> 
<br> 
<label for="Small">Small</label> 
<input type="radio" name="size" id="Small" value="Small" /> 
<label for="Medium" >Medium</label> 
<input type="radio" name="size" id="Medium" value="Medium"/> 
<label for="Large">Large</label> 
<input type="radio" name="size" id="Large" value="Large"/> 
<label for="Xl">Xl</label> 
<input type="radio" name="size" id="Xl" value="Xl"/> 
<br> 
<input type="submit" name="test" value"Submit"> 
</form> 
+0

'cid1'總是被設置,因爲輸入系統將一律發佈,即使它的值是「」; – lampwins 2013-04-26 22:29:38

+0

@lampwins它的解決方案是什麼? – 2013-04-26 22:30:34

回答

1

也許你應該嘗試

if(is_numeric($_SESSION['cid1'])) 
{ 
    echo "Accessories"; 
} 
else 
{ 
    echo $new_sizes; 
} 
1
Re-Write code like this: 

<?php 
    session_start(); 
    session_destroy(); 
    session_start(); 
    if (empty($_POST) === false) { 
     if (empty($_POST['size']) === false) { 
    $_SESSION['size1']=$_POST['size']; 
      echo $new_sizes = $_POST['size']; 
     } else if (empty($_POST['cid']) === false) { 
     $_SESSION['cid1']=$_POST['cid']; 
      echo "Accessories"; 
     } 
    } 
    ?>