尝试运行一个非常简单的更新查询 - 我没有错误;但是,行也不会更新。这是代码:
try {
require 'connect.php';
$id = $_POST['id'];
$rtn = $_POST['rtn'];
$project_name = $_POST['project_name'];
$staff_assigned = $_POST['staff_assigned'];
$current_status = $_POST['current_status'];
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
$building = $_POST['building'];
$department = $_POST['department'];
$department_contact = $_POST['department_contact'];
$facilities_contact = $_POST['facilities_contact'];
$device_count = $_POST['device_count'];
$project_overview = $_POST['project_overview'];
$sql = "UPDATE projects_list SET rtn=:rtn, project_name=:project_name, staff_assigned=:staff_assigned, current_status=:current_status, start_date=:start_date, end_date=:end_date, building=:building, department=:department, department_contact=:department_contact, facilities_contact=:facilities_contact, device_count=:device_count, project_overview=:project_overview WHERE id=:id";
$stmt = $db->prepare($sql);
$stmt->bindParam(':rtn', $rtn, PDO::PARAM_INT);
$stmt->bindParam(':project_name', $project_name, PDO::PARAM_STR);
$stmt->bindParam(':staff_assigned', $staff_assigned, PDO::PARAM_STR);
$stmt->bindParam(':current_status', $current_status, PDO::PARAM_STR);
$stmt->bindParam(':start_date', $start_date, PDO::PARAM_STR);
$stmt->bindParam(':end_date', $end_date, PDO::PARAM_STR);
$stmt->bindParam(':building', $building, PDO::PARAM_STR);
$stmt->bindParam(':department', $department, PDO::PARAM_STR);
$stmt->bindParam(':department_contact', $department_contact, PDO::PARAM_STR);
$stmt->bindParam(':facilities_contact', $facilities_contact, PDO::PARAM_STR);
$stmt->bindParam(':device_count', $device_count, PDO::PARAM_STR);
$stmt->bindParam(':project_overview', $project_overview, PDO::PARAM_STR);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
}
catch (PDOException $stmt) {
echo $stmt->getMessage();
}
似乎很简单;但是,我已经在Stack和/或Google的许多类似答案中尝试过许多不同的建议,但似乎无法解决这个问题。任何帮助表示赞赏!
编辑:连接代码:
try {
$db = new PDO('mysql:host=localhost;dbname=projects;charset=utf8mb4', $user, $pass);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>