我遇到了问题。这是我编辑文章的代码。我不知道为什么,但我的更新不起作用。它只是重定向到../index.php。我尝试了一切( 引号和东西也.. .. ..你能帮助我吗?我只想编辑/更新标题和内容。代码如下。非常感谢。
editarticle.php
<?php
session_start();
include_once('../connect.php');
include_once('../includes/article.php');
header('Content-type: text/html; charset=utf-8');
if(isset($_SESSION["user_id"])){
$query=$pdo->prepare("SELECT * FROM users WHERE id = "
.$_SESSION["user_id"] );
$query->execute();
$row=$query->fetch(PDO::FETCH_ASSOC);
if($row['privileges']==1){
$query = $pdo->prepare("SELECT * FROM `articles` WHERE article_id='" .
$_POST['id'] . "'");
$query->execute();
$row=$query->fetch(PDO::FETCH_ASSOC);
var_dump($row);
if(isset($_POST['editarticle'])){
if(isset($_POST['title'], $_POST['content'])){
$title= $_POST['title'];
$content= nl2br($_POST['content']);
$query= $pdo->prepare("UPDATE `articles` SET article_title="
.$_POST['title'] .",article_content=" .$_POST['content'] ." WHERE
article_id='" . $_POST['id'] . "'");
$query->execute();
$row=$query->fetch(PDO::FETCH_ASSOC);
header('Location: ../index.php');
}
}
?>
<html>
<head>
<title>CMS Tutorial</title>
<link rel="stylesheet" href="assets/style.css" />
</head>
<body>
<div class="container">
<br/>
<h4>Upravit prispevok</h4>
<?php if(isset($error)){
echo $error;
}?>
<? $query = $pdo->prepare("SELECT * FROM `articles` WHERE article_id='"
. $_POST['id'] . "'");
$query->execute();
$row=$query->fetch(PDO::FETCH_ASSOC);
?>
<form action="editarticle.php" method="post" autocomplete="off"
class="addarticle">
<input type="text" name="title" value="<?php echo
ucwords($row['article_title']);?>"/><br/><br/>
<textarea rows="15" cols="50" name="content"><?php echo
ucwords($row['article_content']);?></textarea><br/><br/>
<input type="submit" name="editarticle" value="Upraviť prispevok"/>
</form>
</div>
</body>
</html>
<?php
} } else{
header('Location: index.php');
}
?>