让我试着解释一下我在这里发生了什么。这是一个成员区域,单击一个按钮时,将调用此脚本。理想情况下,它会减去项目的成本(点数),并使用新的点变量更新数据库。
脚本:
<?php
session_start();
if ($_SESSION['email'])
{
$dbemail=$_SESSION['email'];
//connecting here
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM tsfs_members WHERE email = '$dbemail'");
$row = mysqli_fetch_array($result);
//putting rows into variables to make calling them easier
$id = $row["id"];
$firstname = $row["firstname"];
$lastname = $row["lastname"];
$email = $row["email"];
$streetaddress = $row["streetaddress"];
$city = $row["city"];
$state = $row["state"];
$zip = $row["zip"];
$points = $row["points"];
$date = $row["date"];
$newpoints = $points - '75';
$sql = "UPDATE tsfs_members SET points='50' WHERE id=?";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param('s',$id);
$stmt->execute();
echo "Thanks! Your have" . $newpoints . "left in your account";
}
else
{
echo "<div style='text-align:center; color:#ff0000; font-size:200%; margin-top:40px; font-weight:bold;'>You must be a registered user!</div>";
}
?>
这会在非对象
上抛出一个成员函数prepare()的调用错误任何帮助将不胜感激!
答案 0 :(得分:1)
另一个question you asked包含:
mysqli_query($con,"UPDATE feedback SET approved=1 WHERE approved='0'");
对于这个也一样。
如:
$stmt = $con->prepare($sql);
而不是:
$stmt = $mysqli->prepare($sql);
因为您已经使用$con
传递数据库连接:
$result = mysqli_query($con,"SELECT...
$mysqli
未定义,这就是non-object
错误的来源。