我不明白。在这里,我有一段代码,它应该更新我的数据库中的选定行,我收到此错误:SQLSTATE [HY093]:参数号无效:没有参数被绑定。
$id = $_GET['id'];
$blog = DB::getInstance()->query("SELECT * FROM blog WHERE id=$id");
if (isset($_POST['title'])) {
try {
$conn = new PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/db'), Config::get('mysql/username'), Config::get('mysql/password'));
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$title = isset($_POST['title']) ? $_POST['title'] : '';
$category = isset($_POST['category']) ? $_POST['category'] : '';
$intro = isset($_POST['intro']) ? $_POST['intro'] : '';
$body = isset($_POST['body']) ? $_POST['body'] : '';
$sql = "UPDATE blog SET title='$title', category='$category', intro='$intro', body='$body' WHERE id=$id";
$result = $conn->prepare($sql);
$result->execute();
echo $result->rowCount() . ' record updated successfully';
Redirect::to('manage_blog.php');
} catch (PDOException $e) {
echo $sql . '<br />' . $e->getMessage();
}
}
有趣的是,我使用完全相同的代码块()来更新不同的表,并且100%有效。
$job_id = $_GET['job_id'];
$jobs = DB::getInstance()->query("SELECT * FROM jobs WHERE job_id=$job_id");
if (isset($_POST['job_title'])) {
try {
$conn = new PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/db'), Config::get('mysql/username'), Config::get('mysql/password'));
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$job_title = isset($_POST['job_title']) ? $_POST['job_title'] : '';
$date = isset($_POST['date']) ? $_POST['date'] : '';
$location = isset($_POST['location']) ? $_POST['location'] : '';
$type = isset($_POST['type']) ? $_POST['type'] : '';
$description = isset($_POST['description']) ? $_POST['description'] : '';
$education = isset($_POST['education']) ? $_POST['education'] : '';
$experience = isset($_POST['experience']) ? $_POST['experience'] : '';
$competencies = isset($_POST['competencies']) ? $_POST['competencies'] : '';
$how_apply = isset($_POST['how_apply']) ? $_POST['how_apply'] : '';
$sql = "UPDATE jobs SET job_title='$job_title', date='$date', location='$location', type='$type', description='$description', education='$education', experience='$experience', competencies='$competencies', how_apply='$how_apply' WHERE job_id=$job_id";
$result = $conn->prepare($sql);
$result->execute();
echo $result->rowCount() . ' record updated successfully';
Redirect::to('manage_jobs.php');
} catch (PDOException $e) {
echo $sql . '<br />' . $e->getMessage();
}
}
我不知所措。