我正在一個項目上工作,現在我正在製作一個系統,在這裏我用ckeditor編輯帖子。如果我用ckeditor編輯文本,它不會更新,我也沒有看到任何錯誤告訴我什麼是錯的。如果可以,請幫助我。PHP更新查詢不會更新數據庫
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Titillium+Web:400,300,200' rel='stylesheet' type='text/css'>
<meta charset="utf-8">
<script src="//cdn.ckeditor.com/4.5.7/standard/ckeditor.js"></script>
<link rel="stylesheet" type="text/css" href="cke.css">
<title>Nieuws</title>
</head>
<?php
include 'db.php';
include 'repeatForm.php';
if (isset($_POST['id'])) {
if (is_numeric($_POST['id'])) {
$id = $_GET['id'];
$title = $_POST['cTitle'];
$content = $_POST['ed1'];
if ($title == '' || $content == '') {
$error = 'Fout: vul alle velden in';
//laat form zien
repeatForm($id,$title,$content,$error);
} else {
$stmt = $dbcon->prepare("UPDATE content SET contentTitle = :title, contentText = :text WHERE contentId = :nummer");
$stmt->bindParam(':title', $title, PDO::PARAM_STR);
$stmt->bindParam(':content', $content, PDO::PARAM_STR);
$stmt->bindParam(':nummer', $id, PDO::PARAM_STR);
$stmt->execute($title,$content,$id);
header("Location: index.php");
}
} else {
echo "Fout";
header("Location: index.php");
}
}
else {
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0) {
$id = $_GET['id'];
$query = $dbcon->query("SELECT * FROM content WHERE contentId='$id'");
$r = $query->fetch();
if ($r['contentId'] == $id) {
$title = $r['contentTitle'];
$content = $r['contentText'];
}
//laat form zien met variabelen
repeatForm($id,$title,$content);
} else {
echo "No results";
header("refresh:1.5;url='index.php';");
}
}
?>
「*我沒有看到任何錯誤,告訴我什麼是錯*」 - 你找錯誤?可能不會,因爲所有這些'header()'調用都會引發警告。和':text'!=':content' – Qirel
你真的使用兩種方法嗎?爲什麼你需要得到id的方法,如果你使用post方法(is_numeric)檢查它是否是數字? – NormundsP
爲什麼不只是'$ stmt-> execute();'? – Milan