".mysql_error()); $news=mysql_fetch_assoc($result); $news_title=$news['news_title']; $news_content=$news['news_content']; $next_op="update"; break; default: $next_op="save"; break; } /*----輸出----*/ show_page('post_tpl'); /*----所有函數----*/ //顯示錯誤訊息 function error_msg($msg=""){ $passwd_error=" $msg "; return $passwd_error; } //儲存新聞 function save_news(){ //過濾外面傳來的變數 $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(empty($password) or $password!=_POST_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."".mysql_error()); } //更新新聞 function update_news(){ //過濾外面傳來的變數 $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']:""; $sn=isset($_POST['sn'])?intval($_POST['sn']):""; //接收使用者輸入密碼,失敗轉回發布頁 if(empty($password) or $password!=_POST_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="update eznews set news_title='$news_title', news_content='$news_content', ip='$ip', author='$author', post_time=now() where sn='$sn'"; mysql_query($sql) or die($sql."".mysql_error()); } ?> ```
進階搜尋
51人線上 (11人在瀏覽線上書籍)
會員: 0
訪客: 51