ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

PHP parsing Issues

April 13, 2011 5:44pm

Subscribe [2]
  • #1 / Apr 13, 2011 5:44pm

    Bucaneer97

    9 posts

    Hi Everybody!

    I want to get my member Id after beeing logged via a form login
    the problem is that the EE tag {member_id} is not affecting the value to the PHP variable

    this is with output & input parsing mode

    here is my code

    —————————————————————————————————
    <?php
    $id = “{member_id}”;


    <?php    

      connection to the database to have records with my $id  
    ?>
    —————————————————————————————————
    if I do an echo to $id it shows {member_id}

  • #2 / Apr 14, 2011 9:24am

    Sue Crocker

    26054 posts

    Hi, Bucaneer97.

    <?php $id = "{member_id}";
    echo $id;
    ?>

    This works for me with PHP in input mode. But if you notice, you don’t have a closing ?> in your first PHP statement.

    What is it you’re trying to do? If you have your database tables inside the same database container that EE is in, you can just use the exp:query to grab it.

    Does that help?

  • #3 / Apr 14, 2011 10:15am

    Bucaneer97

    9 posts

    Hi Sue Crocker!

    thank you for answer,
    for the close tag I forget it just while writing the post.

    your exemple is working for me too but once data base block is added echo $id is showing {member_id}!
    sql bloc is working verry good I tried it by giving the $id a correct value.


    what I’m trying to do is get records from DB (a table that I created for a specific requirement)

    so It blocks me now tha fact that I could not get back my id! could you help please

    this is a more clear code:
    ——————————————————————————-
    <?php
    $id = “{member_id}”;


    ?><?php    
          $bdd = new PDO(‘mysql:host=localhost;dbname=DBname’,‘userName’, ‘password’);
          $response = $bdd->query(‘select * from table1 as T1 , table2 as T2 where T1.id = T2.r_id and T1.id =’.$id.’‘);
         
          $data = $response->fetch();
          $firstname= $data[‘first’];
          $lastname= $data[‘last’];
         
         
          $br=”<br/>”;
         
          echo $firstname, $br,$lastname;
         
    ?>
    ——————————————————————————————

  • #4 / Apr 14, 2011 11:45am

    Mark Bowen

    12637 posts

    Try this instead :

    <?php
          $bdd = new PDO(‘mysql:host=localhost;dbname=DBname’,‘userName’, ‘password’);
          $response = $bdd->query(‘select * from table1 as T1 , table2 as T2 where T1.id = T2.r_id and T1.id =’.$this->EE->session->userdata['member_id'].’‘);
          
          $data = $response->fetch();
          $firstname= $data[‘first’]; 
          $lastname= $data[‘last’]; 
          
          
          $br=”<br>”;
          
          echo $firstname, $br,$lastname;
          
    ?>

    Hope that helps a bit.

    Best wishes,

    Mark

  • #5 / Apr 14, 2011 2:55pm

    Bucaneer97

    9 posts

    Thanks Professor

    it works that what I was looking for!

    Best wishes

  • #6 / Apr 15, 2011 12:22pm

    Sue Crocker

    26054 posts

    Thanks for the assist, Mark.

    Bucaneer97, Feel free to start a new thread if you have any more questions.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases