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.

Syntax error with custom query

February 11, 2012 6:45am

Subscribe [3]
  • #1 / Feb 11, 2012 6:45am

    susanfw

    62 posts

    I’m trying out the query below to display the logged in member’s purchases made with Simple Commerce. I copied the code from this post
    http://ellislab.com/forums/viewthread/190267/

    When I try to preview, I get a syntax error. Could someone let me know what I have wrong? I’m using EE version 2.3.1.

    I have the following at the top of the template

    <?php
    $member_id = $this->EE->session->userdata['member_id'];
    ?>

    And then the following in the body 

    {exp:query sql="SELECT * FROM exp_simple_commerce_purchases 
                    JOIN exp_simple_commerce_items ON exp_simple_commerce_items.item_id = exp_simple_commerce_purchases.item_id
                    JOIN exp_channel_data ON  exp_simple_commerce_items.entry_id = exp_channel_data.entry_id
                    WHERE exp_simple_commerce_purchases.member_id = '<?php echo $this->EE->session->userdata['member_id'];?>'"}
                    
        <h1>Your Courses</h1>
         <a href="http://{field_id_11}"><h3>{field_id_9}</h3><p></a><br />
         {field_id_10}<br />
                   <br />
        {if no_results}<br />
        <h1>Your Courses</h1><br />
        You have not yet purchased any courses.<br />
        {/if}<br />
    {/exp:query}

     

    Thanks
    Susan

  • #2 / Feb 11, 2012 7:18am

    Bhashkar Yadav

    727 posts

    Please check the proper preference of template for “PHP Parsing Stage” also if you are using “Allow PHP?”

  • #3 / Feb 11, 2012 10:54am

    susanfw

    62 posts

    PHP is allowed, PHP Parsing stage was set to Output when I get the syntax error. If I change it to Input, I get the following error

    Parse error: syntax error, unexpected T_VARIABLE in /home/system//expressionengine/libraries/Functions.php(656) : eval()‘d code on line 2

    Susan

  • #4 / Feb 11, 2012 12:05pm

    the3mus1can

    426 posts

    It should be set to parse on input.

    Try this at the top of the page instead.  You could have a hidden character in the whitespace that is causing a PHP error to be thrown.

    <?php $member_id = $this->EE->session->userdata['member_id']; ?>
  • #5 / Feb 11, 2012 8:45pm

    susanfw

    62 posts

    The error changed when I copied your code to the top of the template. The error now ends with line 20 instead of 2.  The rest is the same.

    Custom queries are new to me and I’m don’t know what to look for in regard to syntax errors.

    I appreciate an experienced eye.
    Susan

  • #6 / Feb 11, 2012 10:55pm

    Bhashkar Yadav

    727 posts

    just wondering, if you are creating super object:

    $this->EE =& get_instance();
  • #7 / Feb 12, 2012 5:10am

    susanfw

    62 posts

    I’m not familiar with the term ‘super object’. I looked it up in the User Guide, and in the forum, but still don’t understand.

    I was afraid that the problem might be related to my using the Zoo Visitor add-on to help with some membership functions I needed, so I set up Simple Commerce on another site without Zoo Vistor, and got the same error message with the above code.

    The error message seems to be referring to this line in the code

    WHERE exp_simple_commerce_purchases.member_id = '<?php echo $this->EE->session->userdata['member_id'];?>'"}

    Susan

  • #8 / Feb 13, 2012 12:24am

    Bhashkar Yadav

    727 posts

    <?php
    $this->EE =& get_instance(); 
    $member_id = $this->EE->session->userdata['member_id'];
    ?> 
    
    {exp:query sql="SELECT * FROM exp_simple_commerce_purchases 
                    JOIN exp_simple_commerce_items ON exp_simple_commerce_items.item_id = exp_simple_commerce_purchases.item_id
                    JOIN exp_channel_data ON  exp_simple_commerce_items.entry_id = exp_channel_data.entry_id
                    WHERE exp_simple_commerce_purchases.member_id = '<?php echo $member_id;?>'"}
                    
        <h1>Your Courses</h1>
         <a href="http://{field_id_11}"><h3>{field_id_9}</h3><p></a><br />
         {field_id_10}<br />
                   <br />
        {if no_results}<br />
        <h1>Your Courses</h1><br />
        You have not yet purchased any courses.<br />
        {/if}<br />
    {/exp:query}

    please make sure that template preference of “PHP Parsing Stage” should be selected as “Input” with “Allow PHP” as “Yes”.

  • #9 / Feb 13, 2012 8:29pm

    susanfw

    62 posts

    I finally got this to work by completely removing the PHP code at the top of the template, and just leaving the query in place.

    Thank you to Bhashkar and the3mus1can for your help. I think I’d better start more about queries.

    Susan

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

ExpressionEngine News!

#eecms, #events, #releases