1

I'm storing session data in $relnum variable, as shown below:

if (!isset($_SESSION)) {
    session_start();
    $_SESSION['releasen'] =$_POST['release_no'];
    $relnum=  $_SESSION['releasen']; 
}

And displaying it in form text field, as shown below;

<input name="relnu" id="relnu" type="text" value="<?php if ($rel==''){ echo $relnum;} else echo $rel; ?>" readonly="true"/>

I am submitting above Form data in mysql, as shown below;

if (isset($_POST['submitM']))  {
    $faultd=$_POST['faultdistribution'];
    $faultdes=$_POST['faultdescription'];
    $faultsev=$_POST['faultseverity'];
    $faultt=$_POST['faulttype'];
    $faultn=$_POST['faultcmnt'];
    $rel=$_POST['relnu'];
    $query = mysql_query("INSERT INTO `fault` (`fault-cmnt`,`fault-type`, `release_no`, `fault-discription`, `fault-severity`, `fault-distribution`) VALUES ('$faultn','$faultt', '$rel', '$faultd', '$faultsev', '$faultdes')")
        or die(mysql_error());
    echo "Data Added sucessfully";
}

The data is successfully submitted, but after that $relnum variable displays nothing. I am unable to comprehend what is the reason, as i am storing the data in session.

P.S: I am not using unset.

Please help, what i am missing?

4

5 回答 5

2

您无需在表单中发布会话数据,否则您的代码看起来不错。您可以通过以下形式发布它来轻松完成:

if (isset($_POST['submitM']))  {
    session_start();
    $faultd=$_POST['faultdistribution'];
    $faultdes=$_POST['faultdescription'];
    $faultsev=$_POST['faultseverity'];
    $faultt=$_POST['faulttype'];
    $faultn=$_POST['faultcmnt'];
    $rel=$_SESSION['releasen'];
    $query = mysql_query("INSERT INTO `fault` (`fault-cmnt`,`fault-type`, `release_no`, `fault-discription`, `fault-severity`, `fault-distribution`) VALUES ('$faultn','$faultt', '$rel', '$faultd', '$faultsev', '$faultdes')")
        or die(mysql_error());
    echo "Data Added sucessfully";
}

它会正常工作,请测试它。

谢谢

于 2013-09-12T12:18:50.190 回答
1

会话变量是$_SESSION['releasen']. 这就是每次您session_start();在代码顶部时都可以使用的内容。如果要使用 $relnum,则必须$_SESSION['releasen']在每次页面加载时将 $relnum 设置为等于。

于 2013-09-12T13:02:12.697 回答
1

你可以试试下面的代码:

if (isset($_POST['release_no']) && !empty($_POST['release_no'])) {
    session_start();
    $_SESSION['releasen'] =$_POST['release_no'];
    $relnum=  $_SESSION['releasen']; 
}
于 2013-09-12T12:39:14.377 回答
1

请记住session_start()仅将变量临时存储在服务器端,检查session_start()每个页面上是否有您,检查是否在该页面上回显您的会话变量,如果它没有回显任何内容,请检查您之前从哪里制作会话变量,它可以提供帮助你自己解决你的问题。

于 2013-09-12T12:20:07.693 回答
0

利用

session_unset();
session_destroy();

希望这有帮助

于 2013-09-12T12:13:46.717 回答