• Resolved ehbloom

    (@ehbloom)


    I’m trying to pass a date range through the URL – It all makes sense but I can’t save a report with an error and I keep getting an error when I try to save – here’s my sql query without the parameters:
    SELECT * FROM 40e_rg_lead WHERE form_id=4 && status=”active” and date_created BETWEEN “2018-01-01” and “2018-02-01”

    Here’s what I’m using with the parameters

    SELECT * FROM 40e_rg_lead WHERE form_id=4 && status=”active” and date_created between date(‘<?php $_GET[date_from]; ?>’) and date(‘<?php $_GET[date_to]; ?>’)

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Eli

    (@scheeeli)

    The plugin was designed to not save a query with syntax errors because you could not get any results from such a report, but either of those should work as far as syntax goes.

    I don’t have your 40e_rg_lead table in my test database but this query is pretty much that same and it works for me:
    SELECT ID FROM wp_posts WHERE post_author=1 && post_status=”publish” AND post_date BETWEEN “<?php $_GET[date_from]; ?>” AND date(‘<?php $_GET[date_to]; ?>’)

    Notice that I used “&&” and “AND”, just like you. I also used single-quotes and double-quotes, and it seems to work fine for me if I use the date function or not. So my question for you is: What is the SQL error that you are getting that prevents you form executing (and thus saving) this query?

    Thread Starter ehbloom

    (@ehbloom)

    I can get your exact code to save but it returns nothing.

    I’ve tried this:

    SELECT * FROM 40e_postmeta WHERE post_author=1 && post_date BETWEEN “<?php $_GET[date_from]; ?>” AND “<?php $_GET[date_to]; ?>”

    and get this error:

    Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”’” AND ”’ at line 1

    Plugin Author Eli

    (@scheeeli)

    Make sure to retype the quotes from these examples, this WordPress forum re-formats with “pretty quotes” which will not work in a query. I think that is what your error is about in this case. Actually, maybe it’s because there are no post_author or post_date fields in the postmeta table

    Thread Starter ehbloom

    (@ehbloom)

    That was it!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘passing parameters’ is closed to new replies.