timmah1 Posted January 6, 2009 Share Posted January 6, 2009 I get no errors or no results with this. $sport = $_GET['sports']; $query = "SELECT * FROM articles WHERE sport = '$sport' AND publish = '".date('Y-m-d')."'"; If I hard-code the variables in like this $query = "SELECT * FROM articles WHERE sport = 'nba' AND publish = '2009-01-05'"; Can someone tell me why? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/ Share on other sites More sharing options...
Maq Posted January 6, 2009 Share Posted January 6, 2009 What do you get when you echo out $query in the first example? You've probably done this but did you add or die(mysql_error()) to your mysql_query()? Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730434 Share on other sites More sharing options...
premiso Posted January 6, 2009 Share Posted January 6, 2009 Are you running mysql_query on the query? Or you checking if it errors out? You should really do mysql_real_escape_string on $_GET['sports'] as if you have a ' in that get statement it will cause an error. And it leaves you open to SQL Injection. Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730437 Share on other sites More sharing options...
timmah1 Posted January 6, 2009 Author Share Posted January 6, 2009 When I echo $query, I get this SELECT * FROM articles WHERE sport = 'nba' AND publish = '2009-01-05' Just what I need, but no results The code is like so $query = "SELECT * FROM articles WHERE sport = '$sport' AND publish = '".date('Y-m-d')."'"; $q = mysql_query($query); while ($a = mysql_fetch_array($q)) { echo $a['article']; } Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730441 Share on other sites More sharing options...
Maq Posted January 6, 2009 Share Posted January 6, 2009 Holy. Crap. I beg of you people to put OR die(mysql_error()) after your queries so you can see what's going on. =/ I thought DarkWater already set you straight... Add or die(mysql_error()) at the end of your query! Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730444 Share on other sites More sharing options...
timmah1 Posted January 6, 2009 Author Share Posted January 6, 2009 yes he did, and I've already done that <?php $sport = mysql_real_escape_string($_GET['sports']); $query = "SELECT * FROM articles WHERE sport = '$sport' AND publish = '".date('Y-m-d')."'"; $q = mysql_query($query) or die("Sorry, there was a problem selecting the articles<br /> ".mysql_error()); while ($a = mysql_fetch_array($q)) { echo $a['article']; } ?> With no results, no errors, nothing Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730448 Share on other sites More sharing options...
DarkWater Posted January 6, 2009 Share Posted January 6, 2009 <?php $sport = mysql_real_escape_string($_GET['sports']); $query = "SELECT * FROM articles WHERE sport = '$sports' AND publish = '".date('Y-m-d')."'"; You're using $sports in the query, and setting $sport on the line above it. Pick one. Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730450 Share on other sites More sharing options...
timmah1 Posted January 6, 2009 Author Share Posted January 6, 2009 I corrected it. Must've been while you were typing Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730452 Share on other sites More sharing options...
Maq Posted January 6, 2009 Share Posted January 6, 2009 Are you sure there are results for that query? Everything looks fine to me... Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730454 Share on other sites More sharing options...
redarrow Posted January 6, 2009 Share Posted January 6, 2009 <?php $sport = mysql_real_escape_string($_GET['sports']); $query = "SELECT * FROM articles WHERE sport = '$sports' AND publish = '".date('Y-m-d')."'"; You're using $sports in the query, and setting $sport on the line above it. Pick one. lol sorry was funny. Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730457 Share on other sites More sharing options...
timmah1 Posted January 6, 2009 Author Share Posted January 6, 2009 There are results for the query, I unfortunately was fixing the page, but refreshing a different one. ??? Stupid mistake. Sorry to waste everyone's time, but thanks for the help. Got it working Thanks premiso for the advice Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730458 Share on other sites More sharing options...
Maq Posted January 6, 2009 Share Posted January 6, 2009 There are results for the query, I unfortunately was fixing the page, but refreshing a different one. ??? (middle finger) Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730476 Share on other sites More sharing options...
timmah1 Posted January 6, 2009 Author Share Posted January 6, 2009 Wow! And to think, I had respect for you at one time Maq. Mistakes happen Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730531 Share on other sites More sharing options...
Maq Posted January 6, 2009 Share Posted January 6, 2009 Wow! And to think, I had respect for you at one time Maq. Mistakes happen I'm just kidding, timmah! Quote Link to comment https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/#findComment-730533 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.