Reputation: 175
I have read the PHP manual for over an hour and tried to google the answer but to no avail :(
$stmt = $mysqli->prepare("UPDATE players SET energy=:energy, confidence=:confidence, morale=:morale WHERE playerID=:playerID ");
$stmt->bindParam(':energy', $energy);
$stmt->bindParam(':confidence', $confidence);
$stmt->bindParam(':morale', $morale);
$stmt->bindParam(':playerID', $playerID);
$playerID=1;
$energy = 1000;
$confidence = 1100;
$morale = 1200;
$stmt->execute();
but when I try to run it I get the following error
Fatal error: Call to a member function prepare() on a non-object in /home/www/websites/www.cricket.cliftonbazaar.com/gm/rungame/rungame.php on line 136
Note that line 136 is the PREPARE line.
EDIT : All variable and table names are correct, they have been triple checked.
Upvotes: 0
Views: 125
Reputation: 88657
The problem lies before the code you have posted. If you var_dump($mysqli);
you will find that it is not what you think it is (my guess is that it is FALSE
). If you post the code where you create the mysqli object, we can help you figure out exactly where the problem lies.
Also, you appear to be assigning values after you have used them ($playerID
etc), you need to move those 4 lines above the $stmt->bindParam()
calls. While it may work, what you have done is not strictly correct and may result in undefined variable errors.
Upvotes: 2