0

I've gone over this script like 30 times, and I can't for the life of me find my problem. Here is the code:

function redeem() {

        $case = $_POST["case"]; 
        $name = $_POST["name"]; 
        $profession = $_POST["profession"];
        $city = $_POST["city"];
        $country = $_POST["country"];
        $totalpercent = $_POST["totalpercent"];
        $pretest = $_POST["pretest"];
        $posttest = $_POST["posttest"];
        $investigationspercent = $_POST["investigationspercent"];
        $timesreset = $_POST["timesreset"];
        $creditsspent = $_POST["creditsspent"];
        $timescompleted = $_POST["timescompleted"];

        //Add the information to the learnent_cases_leaderboard table
        $stmt = $this->db->prepare("INSERT INTO learnent_cases_leaderboard (case, name, profession, city, country, totalpercent, pretest, posttest, investigationspercent, creditsspent, timescompleted, timesreset, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)");

        $stmt->bind_param("sssssiiiiiii", $case, $name, $profession, $city, $country, $totalpercent, $pretest, $posttest, $investigationspercent, $creditsspent, $timescompleted, $timesreset); //the quotations specify the type of variable;
        //See http://php.net/manual/en/mysqli-stmt.bind-param.php for more information on bind_param
        $stmt->execute();
        $stmt->close();

When I look at the error log, it gives me this error message:

Line 105 is this line:

PHP Fatal error: Call to a member function bind_param() on a non-object on line 105

Code:

$stmt->bind_param("sssssiiiiiii", $case, $name, $profession, $city, $country, $totalpercent, $pretest, $posttest, $investigationspercent, $creditsspent, $timescompleted, $timesreset);
2
  • Maybe I'm too rusty with my PHP but I think we need to see how $this->db is declared. It sounds like $this->db->prepare doesn't actually return an object. Commented Aug 7, 2011 at 4:57
  • possible duplicate of Reference - What does this error mean in PHP? Commented Apr 22, 2014 at 2:34

2 Answers 2

4

You never checked that $stmt is an object. In this case, it's more likely to be FALSE, which is what PDO::prepare returns when your query has an error in it.

And your query has an error in it, because you did not delimit your field names in backticks and timestamp is a keyword.

Check for errors after invoking functions from 3rd party APIs, and fix your query.

Sign up to request clarification or add additional context in comments.

3 Comments

+1, note that "case" is also a keyword in mysql and thus also needs to be escaped.
it's the first field in the field list ... learnent_cases_leaderboard (case, ...
Of course...stupid mistakes. Thanks guys! Now that I changed "case" and "timestamp" to different names that don't conflict, the script runs perfectly!
1

First of; always run your queries in the localhost to see if your query executes without error. Next always make sure your the names of the fields and data types corresponds with what you have in your code

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.