更新密码错误

时间:2017-08-10 06:42:34

标签: php pdo

我在更新密码时遇到问题。它一直显示数据库错误,但一切都很好。

我的PHP编码,这里有什么不对吗?

<?php
require ("config1.php");
 if(!empty($_POST)){
$lecID=$_GET['lecID'];
$query = "UPDATE lect SET lecass= :lecass WHERE leID = $leID ";

$query_params=array(':lecass'=> $_POST['leass']);

try{
    $stmt=$db->prepare($query);
    $result=$stmt->execute($query_params);

}catch(PDOException $ex){
    $response["success"]=0;
    $response["message"]="Database Error1. Please try again";
    die(json_encode($response));
    }
}?>

帮我解决这个问题。

1 个答案:

答案 0 :(得分:-2)

您的查询应该是

"UPDATE lecturer SET lecPass=".$query_params[:lec_Pass]." WHERE lecID = $lecID ";

<强>更新

1

$query = "UPDATE lecturer SET lecPass= :lec_Pass WHERE lecID = :lec_id ";

$query_params=array(':lec_Pass' => $_POST['lecPass'],':lec_id' => $_GET['lecID'] );

2

$query = "UPDATE lecturer SET lecPass= ? WHERE lecID = ? ";    
try{
    $stmt = $conn->prepare($query);
    $stmt->bind_param("ss", $lecpass, $lecID);
    $lecpass = $_POST['lecPass'];
    $lecID = $_GET['lecID']; // I think you should use either post or get...
    $stmt->execute();
}

并且,在评论中告诉我为什么你使用get和post两个?