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* 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. 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? 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. 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 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 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
Archived
This topic is now archived and is closed to further replies.