0

I am creating an update proogram that takes the winner and loser of a game and adds their wins, loses, points for and points against to their profle in sql db. I have successfuly written the side for the winner, but when replicating tfor the loser, it iis returning an empty array from sql.

<?php

include("connection.php") ;
$winner= $_POST['win'];

$stmt1= $conn->prepare(' SELECT gamerid, wins, loses, pf, pa FROM fnl WHERE gamerid=? ');

$stmt1-> execute(array($winner)) ;

$rs=$stmt1->fetch(PDO::FETCH_ASSOC) ;


$win= $rs['wins'] + 1;

$pf=$rs['pf'] + $_POST['winpts'];

$pa=$rs['pf'] + $_POST['losspts'];


$stmt2=$conn-> prepare('UPDATE fnl SET wins= ?, pf= ?, pa= ? WHERE gamerid = ? ');


$stmt2 -> execute(array($win,$pf, $pa, $winner));

echo "update successsful"; 
   ?>

For the loser i have:

<?php

include("connection.php") ;

$loser= $_POST['loss'];

$stmt3= $conn->prepare(' SELECT gamerid, wins, loses, pf, pa FROM fnl WHERE gamerid=? ');

$stmt3-> execute(array($loser)) ;

$rs1=$stmt3->fetch(PDO::FETCH_ASSOC);

$rs1 is returning as an empty arrray and i have no idea why.. hopefully it is something simple that i am overlooking.

these are in the same .php file.

Any help greatly appreciated.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Stu Parker
  • 41
  • 6
  • both code are in the same file? – Alive to die - Anant Apr 18 '17 at 04:29
  • @AlivetoDie yes – Stu Parker Apr 18 '17 at 05:17
  • Just for the record. This kind of question is considered off topic here. "My code doesn't work, look at it and tell me what's wrong" is not really a question for multiple reasons. The only question of this kind that could get an answer is one that contains [MCVE](https://phpdelusions.net/pdo/mcve). – Your Common Sense Apr 18 '17 at 05:50
  • i agree that it us fishing, but thw reason for this is that it is a duplicate(literally cut and paste change variable names. of the top code (which works).. the error reporting is set in connection.php, no error is reported, yet i still get an empty array as result. Where i was leading was, Is there some particular qurik of pdo/sql that would cause this or is it a ghost bug. – Stu Parker Apr 18 '17 at 06:42
  • the $rs['win] are user name that on the from are written directly from db.. i see absolutely no reason why it shouldn't work – Stu Parker Apr 18 '17 at 06:45
  • also if this is not the place for such a question, so you have a suggestion on where to go for such help – Stu Parker Apr 18 '17 at 06:49

0 Answers0