Jump to content

Error from query


86Stang

Recommended Posts

My head hurts...

 

I've got this query:

 

"SELECT * FROM mytable WHERE signup_date >= $_POST['start_date'] AND signup_date <= $_POST['end_date'] ORDER BY signup_date DESC"

 

and it's throwing this error:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /path/path/path/filename.php on line 13

 

I've ensured the post data is coming over from the form that starts this query so I'm guessing it has something to do with my syntax?

Link to comment
https://forums.phpfreaks.com/topic/150174-error-from-query/
Share on other sites

the braces should do the trick...also, you can shorten the query:
[code=php:0]$sql = "SELECT * FROM mytable WHERE signup_date BETWEEN {$_POST['start_date']} AND {$_POST['end_date']} ORDER BY signup_date DESC";

 

edit: another note...you should pass the $_POST['start_date'] through mysql_real_escape_string() to sanitize it

Link to comment
https://forums.phpfreaks.com/topic/150174-error-from-query/#findComment-788639
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.