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; }