Session Variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DaedalusShadow
    New Member
    • Mar 2007
    • 8

    Session Variables

    I've got this piece of script:
    [php]
    $schque = $_SESSION['user'];
    $a=$_REQUEST['$schque'];
    $username="daed alus_admin";
    $password="test ";
    $database="daed alus_db";

    mysql_connect(l ocalhost,$usern ame,$password);
    @mysql_select_d b($database) or die( "Unable to select database");
    $query="SELECT * FROM user WHERE username='$a'";
    $result=mysql_q uery($query);
    $num=mysql_numr ows($result);
    [/php]
    Read the Posting Guidelines at the top of this forum, especially the part about enclosing shown code within php or code tags!!!

    moderator


    The problem is that $schque is the correct value, but it won't pass to $a. I've tried put $schque straight into the query but that doesn't work either. Any help would be appriecated.
    Last edited by ronverdonk; Mar 2 '07, 03:04 PM. Reason: place code within tags
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    From your coding You are trying to Fetch the session Variable that you have already created some where(a page) in your Application.

    But to Get that session variable to this page first you have to Add

    [PHP]
    <?
    session_start() ;
    //Then Your Coding.....
    ?>
    [/PHP]

    Comment

    • DaedalusShadow
      New Member
      • Mar 2007
      • 8

      #3
      Originally posted by ajaxrand
      From your coding You are trying to Fetch the session Variable that you have already created some where(a page) in your Application.

      But to Get that session variable to this page first you have to Add

      [PHP]
      <?
      session_start() ;
      //Then Your Coding.....
      ?>
      [/PHP]
      I've got that further up, sorry should have posted it as well.

      It won't take the variable from $schque and put it into $a

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        Try This Sample

        First.php
        [PHP]<?php
        session_start() ;// Sessions Will Start
        //New Session Variable Will Create Here
        $schque = "Sample_Use r";
        $_SESSION['user']= $schque;
        echo '<a href="next.php" >Next Page</a>';
        ?>[/PHP]

        next.php
        [PHP]<?php
        session_start() ;//Here You Have to Start the Session
        $schque = $_SESSION['user'];//Get the Session Created From Prevous Page to A New Variable
        echo $schque;
        ?>[/PHP]

        Comment

        • DaedalusShadow
          New Member
          • Mar 2007
          • 8

          #5
          Originally posted by ajaxrand
          Try This Sample

          First.php
          [PHP]<?php
          session_start() ;// Sessions Will Start
          //New Session Variable Will Create Here
          $schque = "Sample_Use r";
          $_SESSION['user']= $schque;
          echo '<a href="next.php" >Next Page</a>';
          ?>[/PHP]

          next.php
          [PHP]<?php
          session_start() ;//Here You Have to Start the Session
          $schque = $_SESSION['user'];//Get the Session Created From Prevous Page to A New Variable
          echo $schque;
          ?>[/PHP]
          then how do i get $a = $schque so I can use it for

          $query="SELECT * FROM user WHERE username='$a'";

          Comment

          • ak1dnar
            Recognized Expert Top Contributor
            • Jan 2007
            • 1584

            #6
            Your Question is Not Clear.

            From the First page you have to create a Session variable.It may be a User Input something like Login page or etc.

            How ever Create the User session variable from the First Page.
            Then as i showed to you Get it from the Next Pages.

            If you want to PUT that Session varible to SQL Query
            Why again using this
            [PHP]$a=$_REQUEST['$schque'];[/PHP]

            You can directly Pass $schque

            to Your SQL Script Like
            since you have fetched the user value to that Variable
            [PHP]$schque = $_SESSION['user'];
            $query="SELECT * FROM user WHERE username='$schq ue'";[/PHP]

            If this is Not Clear POST All Your Coding Here.Becoz I cant Undestand Your Incomplete Question

            Comment

            • DaedalusShadow
              New Member
              • Mar 2007
              • 8

              #7
              Originally posted by ajaxrand
              Your Question is Not Clear.

              From the First page you have to create a Session variable.It may be a User Input something like Login page or etc.

              How ever Create the User session variable from the First Page.
              Then as i showed to you Get it from the Next Pages.

              If you want to PUT that Session varible to SQL Query
              Why again using this
              [PHP]$a=$_REQUEST['$schque'];[/PHP]

              You can directly Pass $schque

              to Your SQL Script Like
              since you have fetched the user value to that Variable
              [PHP]$schque = $_SESSION['user'];
              $query="SELECT * FROM user WHERE username='$schq ue'";[/PHP]

              If this is Not Clear POST All Your Coding Here.Becoz I cant Undestand Your Incomplete Question
              Thanks that worked, I was being stupid as per usual, sorry for being confusing.

              Comment

              • ak1dnar
                Recognized Expert Top Contributor
                • Jan 2007
                • 1584

                #8
                Originally posted by DaedalusShadow
                Thanks that worked, I was being stupid as per usual, sorry for being confusing.
                Its a pleasure to here that.You are warmly welcome anytime.
                :) Ajaxrand

                Comment

                Working...