#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    17
    Rep Power
    0

    How to assign SELECT query results to a SESSION var


    I have a Select query running at user login to capture the results of 3 fields of a single row which I need to use on another page. My query is as follows:-
    PHP Code:
    $qry "SELECT SType1_Desc, Stype2_Desc, SType3_Desc FROM patient WHERE UID = '".$login."'";
        
    $result = @mysql_query($qry);
        if(!
    $result) {
        die(
    'Failed to Update ' mysql_error());
        } else {
        
        if (
    mysql_num_rows($result)==1){ 
        
        
    $row mysql_fetch_array($result); 
        
    $_SESSION['Desc1'] = mysql_result($row,"SType1_Desc");
        
    $_SESSION['Desc2'] = mysql_result($row,"SType2_Desc");
        
    $_SESSION['Desc3'] = mysql_result($row,"SType3_Desc");
        
    print_r($_session); 


        
        }else {
        echo 
    "Not found";
        }
        } 
    The SESSSIOn vars are subsequently used for a popup and coded as follows:-

    PHP Code:
    <table width="39%" height="50" border="1" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000">
      <!--setting table properties -->
      <td width="18%" align="center">Type</td>
      <td width="82%" align="center">Description</td>
      </tr>
      <tr> 
        <td align="center">Type 1&nbsp</td>
        <td align="center"><?php echo $_SESSION['Desc1'];?>
          <div align="left">&nbsp;</div></td>   
      </tr>
      <tr> 
        <td align="center">Type 2&nbsp</td>
        <td align="center"><?php echo $_SESSION['Desc2'];?>
          <div align="left">&nbsp;</div></td>   
      </tr>
      <tr> 
        <td align="center">Type 3&nbsp</td>
        <td align="center"><?php $_SESSION['Desc3'];?>
          <div align="left">&nbsp;</div></td>   
      </tr>
    </table>
    <?php
    print_r
    ($_SESSION); 
    ?>
    As you can see above, I have inserted the print_r($_SESSION); to capture the results and this is showing that the Desc1,2 & 3 are empty. I realise I must have something wrong with my syntax but, as a novice I have no idea were to start. My errors state undefined index and am aware that this points to something within the array but need some advice on what to do.
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,555
    Rep Power
    2338
    Is there a session_start() call at the top of your page?
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  4. #3
  5. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,295
    Rep Power
    9400
    Turn on display_errors and set error_reporting=-1 in your php.ini, restart Apache, and run the login thing again. You will see one error message repeated three times (potentially among others). It will talk about a function. Look up the function in the PHP manual, learn how to use it, adjust your code so that you use it correctly (which, in this case, is not even using it at all), and try again.

    Comments on this post

    • ptr2void agrees : Forest for the trees!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    17
    Rep Power
    0
    Originally Posted by requinix
    Turn on display_errors and set error_reporting=-1 in your php.ini, restart Apache, and run the login thing again. You will see one error message repeated three times (potentially among others). It will talk about a function. Look up the function in the PHP manual, learn how to use it, adjust your code so that you use it correctly (which, in this case, is not even using it at all), and try again.
    Hi requinix

    As a complete novice I do not find your answer very useful. I was of the opinion that this forum was here to guide and help people who were less proficient. Your response, whilst welcome, appears to mock my inability rather than assist. However I will try to follow what you have recomeded.
    My code submitted was advised by a google search and, whilst I can understand the syntax is incorrect I was rather hoping for some practical guidance with this.

    Comments on this post

    • ptr2void disagrees : If you want to become something *other* than a novice, you'll follow requinix's sage advice so that you might learn something and become a good programmer. Don't expect your hand being held constantly!
    • aeternus disagrees : requinix, just explained you in detail how to debug your code. THat is not only usefull for this case but also in all your future coding adventures. novice or not

IMN logo majestic logo threadwatch logo seochat tools logo