MarkDown
";
return $passwd_error;
}
//儲存新聞
function save_news(){
global $passwd;
//過濾外面傳來的變數
$op=isset($_POST['op'])?$_POST['op']:"";
$password=isset($_POST['password'])?$_POST['password']:"";
$news_title=isset($_POST['news_title'])?$_POST['news_title']:"";
$news_content=isset($_POST['news_content'])?$_POST['news_content']:"";
$author=isset($_POST['author'])?$_POST['author']:"";
//接收使用者輸入密碼,失敗轉回發布頁
if($op=="save" && (empty($password) or $password!=$passwd)){
// 產生 cookie
// setcookie('news_title',$news_title);
// setcookie('news_content',$news_content);
// 產生 session,以記住剛剛使用者輸入的資料,避免需要重打
$_SESSION['news_title']=$news_title;
$_SESSION['news_content']=$news_content;
//轉回編輯頁面,並用 get 方式,傳遞 $op 以便顯示密碼有誤的訊息
header("location:{$_SERVER['PHP_SELF']}?op=passwd_error");
exit;
}else{
// nl2br()將換行符號轉換為
標籤
//$news_content=nl2br($news_content);
// 發布正確,剛剛輸入的內容無需在記住,因此清空之。
$_SESSION['news_title']=$_SESSION['news_content']='';
}
if(!link_db()){
$_SESSION['news_title']=$news_title;
$_SESSION['news_content']=$news_content;
//轉回編輯頁面,並用 get 方式,傳遞 $op 以便顯示密碼有誤的訊息
header("location:{$_SERVER['PHP_SELF']}?op=db_error");
exit;
}
//存到資料庫
$sql="insert into eznews (news_title, news_content, ip, author, post_time) values('$news_title', '$news_content', '$ip', '$author', now())";
mysql_query($sql) or die($sql."