php - Session Doesnt work first time (want explanation )
Hello i am seen lot of question like Session doesn't working first time. But couldn't see any good explanation on this question and why doesn't working first time also what is happening during sessioning. Mine is also like others first time doesn't working after that works fine.
this is php which is sessioning.
session_start();
$PersonName=$_GET['PersonName'];
$SurName=$_GET['SurName'];
$TestXML=$_GET['TestXML'];
$TestDate=$_GET['TestDate'];
$TestPkID='0000000000000000000000000000';
include('DBConnect.php');
$proc = "{call p_set_Test(?,?,?,?,?,?,?,?,?)}";
$params = array(array($TestDate,SQLSRV_PARAM_IN),
array(0,SQLSRV_PARAM_IN),
array($PersonName,SQLSRV_PARAM_IN),
array($SurName,SQLSRV_PARAM_IN),
array($TestXML,SQLSRV_PARAM_IN),
array('',SQLSRV_PARAM_IN),
array(101,SQLSRV_PARAM_IN),
array(10,SQLSRV_PARAM_IN),
array($TestPkID, SQLSRV_PARAM_OUT)
);
$result = sqlsrv_query( $conn, $proc, $params);
if( $result === false )
{
echo "Error in executing statement 3.\n";
die( print_r( sqlsrv_errors(), true));
$message2 = "aldaatai";
echo "<script type='text/javascript'>alert('$message2 ' + $TestPkID);</script>";
}
$_SESSION['idpktestsession'] = $_POST["idpktest"] = $TestPkID;
$_SESSION['persontestname'] =$_POST['persontrollname'] = $PersonName;
$_SESSION['persontestlastname'] =$_POST['persontrolllastname'] = $SurName;
this is getting value from sessioned values
<?php include('DBConnect.php');
session_start();
$diskuserid = $_SESSION['idpktestsession'];
$diskusername = $_SESSION['persontestname'];
$diskuserlastname = $_SESSION['persontestlastname'];
$diskuserlastname = mb_substr($diskuserlastname, 0, 1);
?>
<?php
$proc = "{call p_rpt_Pattern(?,?)}";
$params = array($diskuserid,'M');
$procarr = array();
$result = sqlsrv_query( $conn, $proc, $params);
while ($row = sqlsrv_fetch_array($result))
{?>
<tr>
<td><?php echo $row['PatternCode']?></td>
<td><i class="fa fa-chevron-right rightarrow" > </i></td>
<td><?php echo $row['PatternDesc']?></td>
</tr>
<?php
}
?>
Answer
Solution:
This statement was written incorrect:
If you want to assign the value you can rewrite above statement like this
and if you want to concatenate two values you can rewrite like this
Answer
Solution:
As long this is question wasn't answered i found why it don't work first time. Everytime it sending session to another php with value ,its sending with value after page load so if you some how face this error just assign value before page load or put middle loading php insteand of showing direct.