".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'])?check_input($_POST['news_title']):""; $news_content=isset($_POST['news_content'])?check_input($_POST['news_content']):""; $author=isset($_POST['author'])?check_input($_POST['author']):""; $ip=isset($_POST['ip'])?check_input($_POST['ip']):""; $post_time=isset($_POST['post_time'])?check_input($_POST['post_time']):""; //接收使用者輸入密碼,失敗轉回發布頁 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', '$post_time')"; mysql_query($sql) or die($sql."".mysql_error()); } //更新新聞 function update_news(){ //過濾外面傳來的變數 $password=isset($_POST['password'])?$_POST['password']:""; $news_title=isset($_POST['news_title'])?check_input($_POST['news_title']):""; $news_content=isset($_POST['news_content'])?check_input($_POST['news_content']):""; $author=isset($_POST['author'])?check_input($_POST['author']):""; $ip=isset($_POST['ip'])?check_input($_POST['ip']):""; $post_time=isset($_POST['post_time'])?check_input($_POST['post_time']):""; $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&sn=$sn"); 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='$post_time' where sn='$sn'"; mysql_query($sql) or die($sql."".mysql_error()); } //替特殊符號加入反斜線 function check_input($value){ if (!get_magic_quotes_gpc()){ $value = addslashes($value); } return $value; } ?> ```
進階搜尋
537人線上 (191人在瀏覽線上書籍)
會員: 0
訪客: 537