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 variable within Query Module

July 30, 2012 11:45am

Subscribe [1]
  • #1 / Jul 30, 2012 11:45am

    Creative Lynx

    3 posts

    I am attempting to query a database using the username from a login form.

    I am having trouble understanding if it’s impossible due to parsing order of Expression
    Engine. Should I be performing this in PHP with a manual connection to the database and an AJAX response?

    Please note, the Members Module is not appropriate because I am creating a psudeo login where the password is pre-defined.

    {exp:query sql="SELECT * FROM exp_freeform_entries WHERE email = '<?php $username ?>'"}
                    Result!
                    {if no_results} 
                    Sorry, no results 
                    {/if}
                {/exp:query}

    If anyone could provide a solution I’d be most grateful.

    Thanks

  • #2 / Jul 30, 2012 11:51am

    MadWebDesigns

    147 posts

    Is your php setup to run during Input or Output for your template?

  • #3 / Jul 30, 2012 7:03pm

    Robin Sowell

    13255 posts

    Yep- MadWebDesigns is pointing you the right way.  You have to have your template set to parse php on input for the above to work.  Which of course begs the question of how username is being defined.  If it’s with an EE variable- it will depend on which variable.  If it’s php- such as session userdata, you should be fine.

    That help clarify?

  • #4 / Jul 31, 2012 4:27am

    Creative Lynx

    3 posts

    Thanks for your help. I did have the template parsing php on input but I hadn’t used echo to output the username variable. Here is what I have working:

    {exp:query sql="SELECT * FROM exp_freeform_entries WHERE email = '<?php echo $username ?>'"}
                    <?php $emailCheck = 'result'; ?>
                    
                    {if no_results} 
                    <?php $emailCheck = ''; ?>
                    {/if}
                {/exp:query}

     

  • #5 / Jul 31, 2012 9:21am

    Robin Sowell

    13255 posts

    I really should have thought of that!  Glad you got it working, Creative Lynx.  And thanks for updating us on how you did it.

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

ExpressionEngine News!

#eecms, #events, #releases