-2

So, I'm trying to show people who work for me how much they're making for that day... anyway you could tell me why this just gives me a "0" return?

$sql = "
SELECT SUM(money_earned) as money_earned 
  FROM staff_pay 
 WHERE DATE(time_charged)=CURDATE() 
   AND staff_id={$_SESSION['staff_id']}
";
Strawberry
  • 33,750
  • 13
  • 40
  • 57
  • Echo your query to make sure the staff_id is loading correctly, and also check to make sure there's actually data for today. – aynber Aug 23 '17 at 19:30
  • 3
    [Little Bobby](http://bobby-tables.com/) says **[you are _likely_ at risk for SQL Injection Attacks](https://stackoverflow.com/q/60174/)**. Learn about [Prepared Statements](https://en.wikipedia.org/wiki/Prepared_statement) for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even **[escaping the string](https://stackoverflow.com/q/5741187)** is not safe! I recommend `PDO`, which I [wrote a function for](http://paragoncds.com/grumpy/pdoquery/#function) to make it extremely **easy**, very **clean**, and way more **secure** than using non-parameterized queries. – GrumpyCrouton Aug 23 '17 at 19:40
  • staff_id is loading correctly, and there are definitely records. – Zarathustrian Aug 23 '17 at 22:08
  • 1
    at first, you should try a manual SQL request (via the command line, phpMyAdmin or your favorite tool), so you can figure out whether the issue comes from your SQL request and whether the PHP glue is involved or not. you might also want to replace `SUM(money_earned) as money_earned` with `SUM(money_earned) as money_earned_today` – Gilles Gouaillardet Aug 24 '17 at 00:54

1 Answers1

-1

Try this

$sid = $_SESSION['staff_id'];
$sql = "
SELECT  SUM(money_earned) as money_earned 
FROM staff_pay 
WHERE DATE(time_charged)=CURDATE() 
AND staff_id=$sid";
Hamis Hamis
  • 84
  • 2
  • 9
  • This does **not** answer the question in a _useful_ way. **why** do you believe this is the answer? **how** does it work? Simply telling someone to _change their code_ without any context or meaning does not help them learn what they did wrong, and is also not as useful for future readers. – GrumpyCrouton Aug 23 '17 at 19:40