if和else条件不能处理会话变量?

时间:2013-04-26 22:14:53

标签: php session if-statement

我需要解决这个问题我有两个不同的session variables我希望通过session variable在if和else条件下使用echo消息和单选按钮名称大小值吗?

问题是当我选择单选按钮时,应该显示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>

2 个答案:

答案 0 :(得分:0)

也许你应该尝试

类似

if(is_numeric($_SESSION['cid1'])) 
{
  echo "Accessories";   
}
else
{
  echo $new_sizes;
}

答案 1 :(得分:0)

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";
        }
    }
    ?>