0

我通过 URL 中的链接将字符串值传递到下一页 ,<a href="ApplicationRegister.php?plan=trial"> 就像 $plan = $_GET["plan"]; 这样 $_SESSION['plans'] = $plan;但是在 if 语句之后,即使使用 Session 变量,我也没有得到这个计划的值。

我的完整代码是这样的

 $plan = $_GET["plan"];
    echo $plan;
    $_SESSION['plan'] = $plan;
$plans = $_SESSION['plan'];
    echo $_SESSION['plans'];

    include('connect.php');


        If (isset($_POST['submit']))
        {
            $CompanyName = $_POST['CompanyName'];

            $CompanyEmail = $_POST['CompanyEmail'];
            $CompanyContact = $_POST['CompanyContact'];
            $CompanyAddress = $_POST['CompanyAddress']; 
            $StoreName = $_POST['StoreName'];
            echo $plans;

      $myURL ="$_SERVER[HTTP_HOST]";
                $myURL =$StoreName.'.'.$myURL;

        if (stripos($myURL, 'www.') !== 0) {
           $myURL = 'www.' . $myURL;

        }
        if (stripos($myURL, 'http://') !== 0) {
           $myURL = 'http://' .$myURL;

        }

        if(stripos($myURL, '.com') !== 0) {
            $myURL = $myURL . '.com';

        }
        echo $plans;

            $RegistrationType = $_POST['RegistrationType'];

            $Status = "Active";
            $sql = "select * from plans where planname = '$plans'";
            echo $sql;
            mysql_query($sql) or die (mysql_error());
            $planID = $row['planid'];


            $query1 = "select count(CompanyEmail) from ApplicationRegister where CompanyEmail = '$CompanyEmail'" ;

            $result1 = mysql_query($query1) or die ("ERROR: " . mysql_error());

            $msg = "";
             while ($row = mysql_fetch_array($result1))
             {

                if($row['count(CompanyEmail)'] > 0)
                {
                    $msg = "<font color='red'> <b>This E-mail id is already registered </b></font> ";
                    break;
                }
            }
            if($msg == "")
            {


                $query2 = "select count(URL) from ApplicationRegister where URL = '$myURL' ";
                $result2 = mysql_query($query2) or die ("ERROR: " . mysql_error());
                $msg = "";
                while ($row = mysql_fetch_array($result2))
                {

                    if($row['count(URL)'] > 0)
                    {
                        $msg = "<font color='red'> <b>This Stroename is already registered </b></font> ";
                        break;
                    }
                }
                if($msg == "")
                {
                    $sql = "INSERT INTO ApplicationRegister(planid, CompanyName, CompanyEmail, CompanyContact, CompanyAddress, RegistrationType,                        ApplicationPlan, ApplicationStatus, URL, CreatedDate) VALUES ('$planID', '$CompanyName', '$CompanyEmail', '$CompanyContact',                    '$CompanyAddress', '$RegistrationType', '$plans', '$Status', '$myURL', NOW() )";

                    mysql_query($sql) or die(mysql_error());
                    $id = mysql_insert_id();
                    $_SESSION['application_id'] = $id;

                    if($plans == "trail")
                    {
                        header("Location: userRegister.php");
                        exit();
                    } 
                    else
                    {
                        header("Location : PaymentGateway.php");
                        exit();
                    }
                }
            }
        }

?>

仅在开始时它才包含该值,如果我尝试在 theIf 中显示(isset($_POST['submit']))它显示计划的空白值。不知道要做什么。请建议

编辑 即使像这样使用,它也是一样的。我不知道可能是什么问题:(

    $plan = $_GET["plan"];
    echo $plan;
    $_SESSION['plans'] = $plans;
    echo $_SESSION['plans'];
  // $plan = +$plan; 
    include('connect.php');


        If (isset($_POST['submit']))
        {
            $CompanyName = $_POST['CompanyName'];

            $CompanyEmail = $_POST['CompanyEmail'];
            $CompanyContact = $_POST['CompanyContact'];
            $CompanyAddress = $_POST['CompanyAddress']; 
            $StoreName = $_POST['StoreName'];
            echo $_SESSION['plans'];

已编辑

在 ApplicationRegister.php 中,我已经传递了从上一页获得的 hiddenvalue,如下所示

<input type="hidden" name="plan" value="<?php echo $plan ?>"/>

然后 POST 方法我用过这个。现在我得到了它的价值。谢谢大家

已编辑

if($PlanName == "trail")
                    {

                        header("Location: userRegister.php");
                        exit();
                    } 
                    else
                    {
                        header("Location : PaymentGateway.php");
                        exit();
                    }
4

3 回答 3

3

这是因为您没有session_start()在页面顶部调用。您需要它让您的会话在请求中持续存在(这是会话的重点)

于 2012-07-27T01:59:19.573 回答
0

当有人单击链接时,它将正确设置变量。但是,它不会符合$_POST['submit']逻辑,因为它不是一个帖子,只是一个获取。然后,假设您稍后实际发布到该页面,尝试访问其中的任何内容$_GET将为空,然后将会话变量重置为空。

你的第一页应该有这样的代码

<form action="ApplicationRegister.php" method="post">
    <select name="plan">
        <option value="trial">Trial</option>
    </select>
<input type="submit"/>
</form>

然后,您检查$_POST['plan']$_POST['submit']

于 2012-07-27T02:06:40.480 回答
0

除了不调用之外session_start();,这段代码也是错误的:

$plan = $_GET["plan"];
echo $plan;
$_SESSION['plan'] = $plan;
$plans = $_SESSION['plan'];
echo $_SESSION['plans'];

它应该是:

$plan = $_GET["plan"];
echo $plan;
$_SESSION['plan'] = $plan;
$plans = $_SESSION['plans'];
echo $_SESSION['plans'];

您正在设置 $_SESSION['plan'],然后尝试访问 $_SESSION['plans'].

另外,您是单击链接还是提交form?您说您有一个链接,但您的代码尝试访问从form.

如果您使用的是form,请不要使用链接。相反,使用一个select元素来选择一个计划,然后更改$plan = $_GET["plan"];$plan = $_POST["plan"];

编辑:

对于重定向问题,请尝试以下代码:

echo "<pre>** Plan Name: **\n";
var_dump($PlanName);
echo "</pre>";
if($PlanName == "trail")
    {
        header("Location: userRegister.php");
        exit();
    } 
    else
    {
        header("Location: PaymentGateway.php");
        exit();
}

看看它输出了什么。

于 2012-07-27T02:07:15.830 回答