86Stang Posted March 19, 2009 Share Posted March 19, 2009 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 More sharing options...
lonewolf217 Posted March 19, 2009 Share Posted March 19, 2009 you can try echo'ing the query to make sure it is what you expect you can try this as well (braces around the variables) "SELECT * FROM mytable WHERE signup_date >= {$_POST['start_date']} AND signup_date <= {$_POST['end_date']} ORDER BY signup_date DESC" Link to comment https://forums.phpfreaks.com/topic/150174-error-from-query/#findComment-788634 Share on other sites More sharing options...
rhodesa Posted March 19, 2009 Share Posted March 19, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.