<?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();
}
这是我尝试执行上述代码时收到的错误消息:
在非对象上调用成员函数 prepare()。
知道为什么吗?
必须先实例化mysqli
对象,然后才能使用它
<?php
$mysqli = new mysqli('localhost', 'user', 'pass', 'database');
$mysqli->prepare('SQL STATEMENT');
首先,您需要创建一个数据库连接,然后只有您可以从数据库进行查询。
$mysqli = new mysqli('localhost', 'username', 'password', 'database');
看看这里关于如何创建 mysqli 对象的示例 #1:
http://www.php.net/manual/en/mysqli.construct.php