Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    92
    Thanks
    8
    Thanked 0 Times in 0 Posts

    passing string variables from one page to another in php

    Hi,

    I am passing the string value through link in the URL to the next page like this
    Code:
    <a href="ApplicationRegister.php?plan=trial">
    In the ApplicationRegister.php page, i am getting this value like this
    Code:
     $plan = $_GET["plan"];
    and i will put this into a session variable like this
    Code:
    $_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

    Code:
         $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

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,903
    Thanks
    15
    Thanked 226 Times in 226 Posts
    use session_start(); on all your pages. On the page where you set the variable:
    PHP Code:
    $_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>

  • #3
    New Coder
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    do you have
    PHP Code:
    session_start(); 
    at the top of each page?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •