Jump to content

Using date variable from form in WHERE statement


Recommended Posts

Hello,

 

I have been searching everywhere to figure this out but haven't found anything.  So either it's stupid simple or I'm going about it the wrong way.  Here is my sql code:

 

SELECT p.*, c.bagsrecd, c.recddate, c.locationid

FROM ninlf_received AS c INNER JOIN ninlf_recipient AS p

ON c.recipientid = p.recipientid

WHERE c.recddate >= '$_POST["start"]' AND c.recddate <= '$_POST["end"]'

 

I need to filter the data by the variables from a previous page post.  I am using MySQL 5.0 and will create this as a view.

 

Thanks.

then try something like this

 

$query="SELECT p.*, c.bagsrecd, c.recddate, c.locationid

FROM ninlf_received AS c INNER JOIN ninlf_recipient AS p

ON c.recipientid = p.recipientid

WHERE c.recddate >= ".$_POST['start']."AND c.recddate <= ".$_POST['end'];

 

before running the query first echo ur query like

echo $query;

and then execute if ur varibles are interpreted.

 

 

 

Here is the code again.  Again I'm attempting to have this code run from the mysql database and not from the php page.

 

 

SELECT p.*, c.bagsrecd, c.recddate, c.locationid
FROM ninlf_received AS c INNER JOIN ninlf_recipient AS p
ON c.recipientid = p.recipientid
WHERE c.recddate >= '$_POST["start"]' AND c.recddate <= '$_POST["end"]'

I guess that is my question.  It all works from the page source in the php query, but that's not where I need it.

 

Do you have any recommendations how I can make the mysql source "look or refer" to the $POST variable?

I don't really know what this means.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.