我正在尝试更新和添加文章到自定义编码的博客使用pdo。
我可以阅读和删除罚款,但添加或编辑他们不工作的实时服务器。
它在xampp上运行良好。。。
我已经确保在我的数据库上启用了pdo\umysql扩展。
不知问题出在哪里?
我的编辑邮政编码如下所示:
<?php
//if form has been submitted process it
if(isset($_POST['submit'])){
//collect form data
extract($_POST);
//very basic validation
if($postID ==''){
$error[] = 'This post is missing a valid id!.';
}
if($postTitle ==''){
$error[] = 'Please enter the title.';
}
if($postDesc ==''){
$error[] = 'Please enter the description.';
}
if($postCont ==''){
$error[] = 'Please enter the content.';
}
if(!isset($error)){
try {
$postSlug = slug($postTitle);
//insert into database
$stmt = $db->prepare('UPDATE blog_posts_seo SET postTitle = :postTitle, postSlug = :postSlug, postDesc = :postDesc, postCont = :postCont WHERE postID = :postID') ;
$stmt->execute(array(
':postTitle' => $postTitle,
':postSlug' => $postSlug,
':postDesc' => $postDesc,
':postCont' => $postCont,
':postID' => $postID
));
//delete all items with the current postID
$stmt = $db->prepare('DELETE FROM blog_post_cats WHERE postID = :postID');
$stmt->execute(array(':postID' => $postID));
if(is_array($catID)){
foreach($_POST['catID'] as $catID){
$stmt = $db->prepare('INSERT INTO blog_post_cats (postID,catID)VALUES(:postID,:catID)');
$stmt->execute(array(
':postID' => $postID,
':catID' => $catID
));
}
}
//redirect to index page
header('Location: index.php?action=updated');
exit;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
}
?>
<?php
//check for any errors
if(isset($error)){
foreach($error as $error){
echo $error.'<br />';
}
}
try {
$stmt = $db->prepare('SELECT postID, postTitle, postDesc, postCont FROM blog_posts_seo WHERE postID = :postID') ;
$stmt->execute(array(':postID' => $_GET['id']));
$row = $stmt->fetch();
} catch(PDOException $e) {
echo $e->getMessage();
}
?>
我的地址是
<?php
//if form has been submitted process it
if(isset($_POST['submit'])){
//collect form data
extract($_POST);
//very basic validation
if($postTitle ==''){
$error[] = 'Please enter the title.';
}
if($postDesc ==''){
$error[] = 'Please enter the description.';
}
if($postCont ==''){
$error[] = 'Please enter the content.';
}
if(!isset($error)){
try {
$postSlug = slug($postTitle);
//insert into database
$stmt = $db->prepare('INSERT INTO blog_posts_seo (postTitle,postSlug,postDesc,postCont,postDate) VALUES (:postTitle, :postSlug, :postDesc, :postCont, :postDate)') ;
$stmt->execute(array(
':postTitle' => $postTitle,
':postSlug' => $postSlug,
':postDesc' => $postDesc,
':postCont' => $postCont,
':postDate' => date('Y-m-d H:i:s')
));
$postID = $db->lastInsertId();
//redirect to index page
header('Location: index.php?action=added');
exit;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
}
//check for any errors
if(isset($error)){
foreach($error as $error){
echo '<p class="error">'.$error.'</p>';
}
}
?>
我是否应该检查mysql数据库,或者我的代码中是否有什么东西阻止我的crud在实时环境中工作?
如前所述,xampp上使用的是完全相同的代码(配置文件除外)。
2条答案
按热度按时间egmofgnx1#
问题是如何插入
DATE
. 这是他们之间唯一的区别Insert, update and delete
.最好不要通过php添加它,因为您添加的是当前时间,所以可以让数据库为您添加。
':postDate' => date('Y-m-d H:i:s')
<-让db作为默认参数为now()
或者只是使用TIMESTAMP
可能是最好的。e0uiprwp2#
这可能是服务器端的权限错误,因为您无法编辑(写入)文件或创建新文件。我建议检查数据库的用户权限。
当你说它不起作用时,它会给你什么回报?如果var\u dump或echo用作查询,或者根本不允许执行查询,您是否尝试过它?
更新:最后但并非最不重要的是,配置文件,正如注解所建议的,应该是主要问题。这实际上取决于您如何配置文件以在服务器上工作。包括支票等。