stijn0713 Posted March 16, 2012 Share Posted March 16, 2012 Hello, I get the following 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 'BETWEEN '1800-01-01' AND '2200-01-01'' at line 1 Here is the code: // building query $where = array(); if ( $_GET['sex'] != '') {$where[] = " geslacht = '$sex'"; } if( $_GET['minAge'] != '' && is_numeric($_GET['minAge'])){ $where[] = " geboortedatum < '$minAge'"; } if( $_GET['maxAge'] != '' && is_numeric($_GET['maxAge'])) {$where[] = " geboortedatum >= '$maxAge'"; } $where[] = " TijdRegistratie BETWEEN '$minDatum' AND '$maxDatum'"; // glueing query $sql = "SELECT * FROM respondenten"; if (count($where) > 0){ $sql .= "WHERE ".implode(" AND ", $where);} Can somebody tell me where i've put the wrong quotations? *confused* Quote Link to comment https://forums.phpfreaks.com/topic/259050-sql-syntax-error-with-quotations/ Share on other sites More sharing options...
trq Posted March 16, 2012 Share Posted March 16, 2012 echo $sql so we can see the query. Quote Link to comment https://forums.phpfreaks.com/topic/259050-sql-syntax-error-with-quotations/#findComment-1328008 Share on other sites More sharing options...
stijn0713 Posted March 16, 2012 Author Share Posted March 16, 2012 yes i tried to find the error myself by trying to echo $sql but i can't echo it since i get error. Or can i neglect error somehow? Quote Link to comment https://forums.phpfreaks.com/topic/259050-sql-syntax-error-with-quotations/#findComment-1328012 Share on other sites More sharing options...
trq Posted March 16, 2012 Share Posted March 16, 2012 Just comment out wherever your executing your query and echo it instead. Quote Link to comment https://forums.phpfreaks.com/topic/259050-sql-syntax-error-with-quotations/#findComment-1328014 Share on other sites More sharing options...
stijn0713 Posted March 16, 2012 Author Share Posted March 16, 2012 Ah ok thanks for that suggestion. Here is what i get then: http://trippledee.org/query.php Quote Link to comment https://forums.phpfreaks.com/topic/259050-sql-syntax-error-with-quotations/#findComment-1328015 Share on other sites More sharing options...
stijn0713 Posted March 16, 2012 Author Share Posted March 16, 2012 Ok, it's fixed. i forgot a space before WHERE apparently. Thanks for the echo tip Quote Link to comment https://forums.phpfreaks.com/topic/259050-sql-syntax-error-with-quotations/#findComment-1328017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.