Tuesday, 28 August 2018

Mysql does not count the date lines of my php script

I am trying to count the number of dates that occur for a specific mem_id, however, my count output is always "0"... heres my code:

$datechecker = $postdate;
//$postdate is a date variable that is posted via a form into mysql, stored as a DATE

$sql = mysql_query("SELECT * FROM members WHERE mem_id='$id' AND postdate='$datechecker'");
$Counter = mysql_num_rows($sql);
if($Counter >= 0) {
echo "$datechecker $Counter";
exit();
}

This is the output I get: 2011-01-01 0
Even though I have about 10 occurrences of 2011-01-01, so why does my count say "0"? Can anyone help me solve this, or provide an alternate?

echo the string before you mysql_query it, this will validate if the query is what you expect it to be. You can also use count(*) within the query, instead of using php's mysql_num_rows()
I also hope that you're sanitising your input before you're querying that!

0 comments:

Post a Comment