timmah1 Posted October 1, 2008 Share Posted October 1, 2008 Can somebody tell me why this isn't working? No matter if the data matches or not, it always shoes "You can pick today" <?php session_start(); require("header.php"); require("config.php"); $user = $_SESSION['SESS_USERNAME']; $today = date('Y-m-d'); echo "$user<br>"; echo "$today<br>"; $csql = "SELECT user,picked FROM daily_picks WHERE user = '$user' AND picked = '$today'"; $cres = mysql_query($csql); $numrows = mysql_num_rows($cres); if($numrows == 1){ echo "You have already submitted picks for today"; } else { echo "You can pick today"; } require("footer.php"); ?> With the way the database is now, user matches user and picked matches today. Can somebody tell me what's wrong..... Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/126638-solved-numrows/ Share on other sites More sharing options...
F1Fan Posted October 1, 2008 Share Posted October 1, 2008 What do you get if you echo the $numrows var? Also, what if you tried > 0 rather than ==1? Link to comment https://forums.phpfreaks.com/topic/126638-solved-numrows/#findComment-654868 Share on other sites More sharing options...
timmah1 Posted October 1, 2008 Author Share Posted October 1, 2008 echoing out numrows gives me 6, so to me, it's obvious that there's a match, just not sure why it don't tell me I tried changing it to 0, and I get the same answer "You can pick today" Link to comment https://forums.phpfreaks.com/topic/126638-solved-numrows/#findComment-654871 Share on other sites More sharing options...
severndigital Posted October 1, 2008 Share Posted October 1, 2008 echoing out numrows gives me 6, so to me, it's obvious that there's a match you code is looking for an EXACT match to the number 1 ... if($numrows == 1){ ... try making it look for any number larger than 0 ... if($numrows > 0){ ... that should do it Link to comment https://forums.phpfreaks.com/topic/126638-solved-numrows/#findComment-654874 Share on other sites More sharing options...
F1Fan Posted October 1, 2008 Share Posted October 1, 2008 Now that you've changed the code, re-post it. Link to comment https://forums.phpfreaks.com/topic/126638-solved-numrows/#findComment-654878 Share on other sites More sharing options...
timmah1 Posted October 1, 2008 Author Share Posted October 1, 2008 perfect. That worked. With using if($numrows ==1){ has worked numerous times before on different sites I've done, why wouldn't that work now? Thank you so much Link to comment https://forums.phpfreaks.com/topic/126638-solved-numrows/#findComment-654881 Share on other sites More sharing options...
timmah1 Posted October 1, 2008 Author Share Posted October 1, 2008 Works now. Thanks for all your help <?php session_start(); require("header.php"); require("config.php"); $user = $_SESSION['SESS_USERNAME']; $today = date('Y-m-d'); echo "$user<br>"; echo "$today<br>"; $csql = "SELECT user,picked FROM daily_picks WHERE user = '$user' AND picked = '$today'"; $cres = mysql_query($csql); $numrows = mysql_num_rows($cres); if($numrows > 0){ echo "You have already submitted picks for today"; } else { echo "You can pick today"; } require("footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/126638-solved-numrows/#findComment-654882 Share on other sites More sharing options...
F1Fan Posted October 1, 2008 Share Posted October 1, 2008 Like severndigital said, using ==1 looks for exactly 1. You're returning 6, which is not 1. It probably worked before because your queries were returning only 1, and exactly 1 row. >0 works because 1 and 6 are greater than 0. Link to comment https://forums.phpfreaks.com/topic/126638-solved-numrows/#findComment-654883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.