1

trying to do an update using mysqli, by calling a class function like this:

$nyVaegt = 10;
$navn = 'Ord';

$nyOevelse = new oevelse();
$nyOevelse->opdaterOevelse( $nyVaegt, $navn );

And this is the corresponding class function:

public function opdaterOevelse (
        $nyVaegt,
        $navn)

    {
        $this->nyVaegt = $nyVaegt;
        $this->navn = $navn;

        global $mysqli;

        $stmtopdaterOevelseIHistorik = $mysqli->prepare("UPDATE oevelser SET `vaegt12reps`=? WHERE `navn`='?' VALUES (?, ?)");
        var_dump($stmtopdaterOevelseIHistorik);
        $stmtopdaterOevelseIHistorik->bind_param(
                "ds", 
                $nyVaegt,
                $navn);

        $stmtopdaterOevelseIHistorik->execute();

if ( $stmtopdaterOevelseIHistorik )
       echo "Query success!<br>";
   else
       echo "Query failed!<br>";

      }

If I run it like this, it fails saying that:

Call to a member function bind_param() on a non-object

The error refers to this line:

$stmtopdaterOevelseIHistorik->bind_param(

var_dump responds: bool(false)

So, something goes wrong while binding the parameters, it seems.

If I bypass the variables and call like this:

$stmtopdaterOevelseIHistorik = $mysqli->prepare("UPDATE oevelser SET `vaegt12reps`=100 WHERE `navn`='Ord'");

it works fine...

Tried all kinds of '', ""-variations, but I can't make it work... - any advice from you good people of SO...?

3
  • 1
    Basic debugging: You realize $stmtopdaterOevelseIHistorik is null.. step back until you find where it SHOULD be set. $mysqli->prepare().. ok that's failing. Let's look up the docs. "Returns FALSE if an error occurred" - OK how do I debug a false return value from prepare()... go from there Commented Oct 13, 2014 at 19:07
  • @Fred-ii- - much appreciated, of course I shouldn't add values, works fine now without, thx a million - sometimes you can't see the forest for the trees... Commented Oct 13, 2014 at 19:16
  • @ErikLassen You're welcome Erik. I had deleted my comments and posted it as an answer below. Commented Oct 13, 2014 at 19:16

1 Answer 1

1

Far as I know, UPDATE doesn't use VALUES:

Plus, remove the quotes in ='?' which is the main cause for:

Call to a member function bind_param() on a non-object

Change your existing line to the following:

$stmtopdaterOevelseIHistorik = $mysqli->prepare("UPDATE oevelser SET `vaegt12reps`=? WHERE `navn`=?");
Sign up to request clarification or add additional context in comments.

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.