我想通过从表单获取值来更新MySQL数据库中的一行,并使用update
语句将表单值设置为数据库。问题是执行MySQL查询没有任何错误,但是rowCount()
方法返回零,当我通过PHPMyAdmin检查数据库时,它不受影响。这是代码:
elseif(@$do== 'Update'){
echo "<div class='container'>";
echo "<h1 class='text-center'>Update</h1>";
if($_SERVER['REQUEST_METHOD']=='POST'){
//get variables from the form
$id = $_POST['catid'];
$mname = $_POST['name'];
$mdescription = $_POST['description'];
$mordering = $_POST['ordering'];
$mvisibility = $_POST['visibility'];
$mcommenting = $_POST['commenting'];
$mads = $_POST['ads'];
$mordering = $_POST['ordering'];
$stmt = $con->prepare("UPDATE categories SET Name=?,Description=?,Ordering=? ,Visibility=?,Allow_Comments=? ,Allow_Ads=? WHERE ID=?");
$stmt->execute(array($mname,$mdescription,$mordering,$mvisibility,$mcommenting,$mads,$id));
//echo success message
echo '<div class="alert alert-success">'.$stmt->rowCount().'Record updated </div>';
}
else{
echo'<div class= "alert alert-danger">sorry you cant browsethis page directly</div>';
}
echo "</div>";
}
我想念什么?