0

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

问题是当我选择单选按钮时,它应该显示size values而不是accessories

例如我想要这样

如果输入值像任何数字

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

Else If Radio 选择

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>
4

2 回答 2

0

也许你应该试试

就像是

if(is_numeric($_SESSION['cid1'])) 
{
  echo "Accessories";   
}
else
{
  echo $new_sizes;
}
于 2013-04-26T22:25:44.177 回答
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";
        }
    }
    ?>
于 2013-04-26T22:31:36.517 回答