...

View Full Version : passing string variables from one page to another in php



Mythri
07-27-2012, 02:59 AM
Hi,

I am passing the string value through link in the URL to the next page like this
<a href="ApplicationRegister.php?plan=trial">
In the ApplicationRegister.php page, i am getting this value like this
$plan = $_GET["plan"];
and i will put this into a session variable like this
$_SESSION['plans'] = $plan;
Here i am getting the value. but after the if statement i am not getting the value for this plan even after using Session variable.

My complete code is like this


$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();
}
}
}
}

?>

Only in the beginning it holds the value , if i try to display it within theIf `(isset($_POST['submit']))` it shows blank value for plans. Do not know what to do. Plz suggest

DrDOS
07-27-2012, 03:21 AM
use session_start(); on all your pages. On the page where you set the variable:


$_SESSION['myvar'] = $myvar;
On the pages where you want to get it:
$myvar = $_SESSION['myvar'];

Use this line wherever it's convenient to view the session status.
<pre><?php print_r($_SESSION); ?></pre>

garrisonian14
07-27-2012, 08:26 AM
You lines

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

you session variable is plan not "plans" so you must echo $_SESSION['plan'];
if you want to echo $plans variable. That must be echo $plans; but after
$plans = $_SESSION['plan'];

And also make sure you have session_start() at top of each page you want to use sessions.

Arcticwarrio
07-27-2012, 10:10 AM
do you have

session_start();

at the top of each page?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum