NoteOnMe博客平台搭建
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

48 righe
1.8 KiB

<?php
require_once "pdo.php";
session_start();
if ( isset($_POST['article']) && isset($_SESSION['user_id']) && isset($_POST['title'])&&isset($_POST['article_type'])) {
if ( isset($_POST['article_id']) &&$_POST['article_id']!=null){
$sql = "UPDATE article SET content=:articles,headline=:headline,category=:category,public=:public WHERE article_id = :id ";
$stmt = $pdo->prepare($sql);
try{
$stmt->execute(array(
':articles' => $_POST['article'],
':headline' => $_POST['title'],
':public' => $_POST['article_type'],
':id'=>$_POST['article_id'],
':category'=>$_POST['category']
));
}catch (Exception $e) {
$_SESSION['error'] = 'fail';
header( 'Location: edit_article.php' ) ;
return;
}
$id=$_POST['article_id'];
}
else{
$sql = "INSERT INTO article (content,user_id,headline,public,category,viewer) VALUES (:articles, :user_id,:headline,:public,:category,:viwer)";
$stmt = $pdo->prepare($sql);
try{
$stmt->execute(array(
':articles' => $_POST['article'],
':user_id' => $_SESSION['user_id'],
':headline' => $_POST['title'],
'viwer'=>0,
':public' => $_POST['article_type'],
':category'=>$_POST['category']
));
}catch (Exception $e) {
$_SESSION['error'] = 'fail';
header( 'Location: edit_article.php' ) ;
return;
}
$id=$pdo->lastInsertId();
}
$_SESSION['success'] = '保存成功';
header( 'Location:view.php?article_id='.$id ) ;
return;
}