0

Before I ask my question I wanted to say I have looked at many other solutions and have tried tons of different ones but none work for me. I understand that to call the bind_param() the $sql variable cannot return false, and that's why I am getting the error. I have triple checked the table name, and column names but I will include a picture to help. I honestly have tried everything and googled for a good hour or two, any help would be greatly appreciated. And yes the database connection works, its been tested with 3 other functions. I will close this question as soon as it is answered because I know there are tons of these.

My database

function updateScore() {
$conn = connectDB();

// Score Update
$name = "happy";
// $name = getName();
$sql = $conn->prepare("SELECT Score FROM Names WHERE Name=?");
$sql->bind_param("s",$name);
$sql->execute();
$sql->bind_result($score);
$sql->fetch();

echo "This actually works";
echo "Score Before" .$score;
$score++;
echo "Score After" .$score;

Up to here works like a charm and prints out the updated score to the page, below is problem

$sql = $conn->prepare("UPDATE Names SET Score=? WHERE Name=?");
$sql->bind_param("is",$score, $name);
$sql->execute();
$sql->fetch();

$sql->close();
$conn->close();
} 
  • 1
    how would you know, you haven't even checked the error messages, turn on php error messages and use `$conn->error` – Kevin Apr 28 '16 at 02:08
  • Also remove the `$sql->fetch();` from your second block: `UPDATE` does nor return records. – Norbert Apr 28 '16 at 02:09
  • and just combine it into just one statement `set score = score + 1 where name = ?` – Kevin Apr 28 '16 at 02:09
  • @RodrigoDuterte The error message is in the title. – wilsonzlin Apr 28 '16 at 02:10
  • @lerouche nope, what i meant is the mysql error message, that title could mean a myriad of things – Kevin Apr 28 '16 at 02:11
  • The error in the title is the result of not checking for errors `mysqli` is urgently trying to deliver to you. Every operation that *could* return an error needs to be tested and handled accordingly. This can get very messy, so you might want to turn on [exceptions](http://stackoverflow.com/questions/14578243/turning-query-errors-to-exceptions-in-mysqli) to simplify that. – tadman Apr 28 '16 at 02:27
  • The following link tells the actual problem. [link](http://stackoverflow.com/a/17768237/5709111) – nikamanish Apr 28 '16 at 02:45

0 Answers0