-2
<?php

$dob = $_SESSION['dob'];
$month = $_SESSION['month'];
$s = $_POST['present'];
$p = "1";

if ($stmt = $mysqli->prepare("UPDATE atten SET total = ? WHERE name = ?")) 
{
    // Bind the variables to the parameter as strings. 
    foreach ($s as $name) 
    {
        $stmt->bind_param("ss", $p, $name);

        // Execute the statement.
        $stmt->execute(); 
    }

    // Close the prepared statement.
    $stmt->close();
}

This is the error message I'm getting when I try to execute the above code:

Call to a member function prepare() on a non-object.

Any ideas why?

Amal Murali
  • 75,622
  • 18
  • 128
  • 150

3 Answers3

0

You have to instantiate the mysqli object before you can use it

<?php
$mysqli = new mysqli('localhost', 'user', 'pass', 'database');
$mysqli->prepare('SQL STATEMENT');
Machavity
  • 30,841
  • 27
  • 92
  • 100
0

First you need to create a database connection and then only you can make queries from the database. like

$mysqli = new mysqli('localhost', 'username', 'password', 'database');
Let me see
  • 5,063
  • 9
  • 34
  • 47
0

Have a look at Example #1 here on how to create a mysqli object:

http://www.php.net/manual/en/mysqli.construct.php

Jason Fingar
  • 3,358
  • 1
  • 21
  • 27