日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php手机论坛程序,网站开发-php开发手机论坛(8)-编辑帖子

發布時間:2024/7/23 php 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php手机论坛程序,网站开发-php开发手机论坛(8)-编辑帖子 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

上一篇說了怎么查看帖子,這一篇就來說說怎么把數據庫里面的帖子提取出來編輯.

代碼邏輯是這樣的:

先驗證是否是當前用戶的帖子,是的話就提供編輯按鈕,這個在view.php中實現.

->在數據庫中根據get的a來提取已有帖子數據,加載到模板文件中.

->最后把得到數據更新到數據庫里面,再跳轉到查看帖子

edit.php

include('conn.php');

include('lib.php');

include('ChromePhp.php');

session_start();

// Chromephp::log($_SESSION['uid']);

// Chromephp::log($_SESSION['name']);

//如果會話沒有被設置,查看是否設置了cookie

if(!isset($_SESSION['uid']))

{

if(isset($_COOKIE['uid'])&&isset($_COOKIE['name']))

{

//用cookie給session賦值

$_SESSION['uid']=$_COOKIE['uid'];

$_SESSION['name']=$_COOKIE['name'];

}

else

{

header("Location: login.php");

exit();

}

}

//獲取分類目錄

if($_SERVER['REQUEST_METHOD'] == 'GET')

{

$aid=$_GET['a'];

$sql="select id, name from categories";

$query=mysql_query($sql);

while ($node=mysql_fetch_assoc($query)) {

$category[$node['id']]=$node['name'];

}

//提取已有的帖子內容

$query=mysql_query("select * from articles where id='$aid'");

$article=mysql_fetch_array($query);

ChromePhp::log($article);

include("templates/edit.php");

}

if($_SERVER['REQUEST_METHOD'] == 'POST')

{

//header("Location: index.php") ;

//print_r($category);

$aid=$_GET['a'];

$title=format($_POST['title']);

$content=format($_POST['content']);

$classic=format($_POST['classic']);

//ChromePhp::log($classic);

//更新分類文章數量

$sql="update categories set articles = articles+1 where name = '$classic'";

$query=mysql_query($sql);

//ChromePhp::log($query);

$time=time();

//ChromePhp::log($aid);

//上傳圖片

if ($_FILES['img']['error'] ==0 && ($_FILES['img']['type']=="image/gif"

|| $_FILES['img']['type']=="image/jpeg" || $_FILES['img']['type']=="image/pjpeg"

|| $_FILES['img']['type']=="image/png"

))

{

//判斷錯誤代碼,=0則上傳成功,!=0則上傳失敗

//處理上傳過程

// ChromePhp::log("開始上傳");

$img = $_FILES['img'];

//header("Location: templates/error.php") ;

//exit;

//拼接文件路徑

$path ='upload/'.mk_dir().'/'.randName(). '.' .getExt($img['name']);

// ChromePhp::log($path);

//移動

if(move_uploaded_file($img['tmp_name'],$path)) {

mysql_query("update articles set title='$title', content='$content', category='$classic', edittime='$time', img_path='$path' where id='$aid'");

header("Location: view.php?a=".$aid);

exit();

} else{

ChromePhp::log("上傳失敗");

}

}else

{

mysql_query("update articles set title='$title', content='$content', category='$classic', edittime='$time', img_path='$path' where id='$aid'");

// $url = "http://blog.csdn.net/abandonship";

// echo "

// echo "window.location.href='$url'";

// echo "";

header("Location: view.php?a=".$aid);

exit();

// ChromePhp::log($_FILES['img']['error']);

}

}

?>templates/edit.php

返回

編輯逗貼

enctype="multipart/form-data" data-ajax="false" >'; ?>

  • 標題

    >

  • 內容

  • 請選擇分類:

    foreach ($category as $id => $name) {

    echo '',$name,'

    ';

    }

    ?>

  • 圖片:

總結

以上是生活随笔為你收集整理的php手机论坛程序,网站开发-php开发手机论坛(8)-编辑帖子的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。