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

歡迎訪問 生活随笔!

生活随笔

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

php

php学习实例3

發布時間:2025/3/17 php 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php学习实例3 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  新聞發布管理系統

  路由器action.php

<!DOCTYPE html> <html> <head><title></title><meta charset="utf-8"> </head> <body> <?phprequire("dbconfig.php");$link = @mysql_connect(HOST, USER, PASS) or die("db error");mysql_select_db(DBNAME, $link);echo "action";switch($_GET["action"]) {case "add" :$title = $_POST["title"];$keywords = $_POST["keywords"];$author = $_POST["author"];$content = $_POST["content"];$addtime = time();$sql = "insert into news values(null, '{$title}', '{$keywords}', '{$author}', {$addtime}, '{$content}')";//echo $sql; $link.mysql_query($sql);$id = mysql_insert_id($link);if($id>0) {echo "<a>成功</a>";}else{echo "<a>失敗</a>";}echo "<a href='./index.php'>返回主頁</a>";break;case "del" :$id = $_GET["id"];$sql = "delete from news where id={$id}";mysql_query($sql);header("Location:index.php");break;case "update" :$id = $_POST["id"];$title = $_POST["title"];$keywords = $_POST["keywords"];$author = $_POST["author"];$content = $_POST["content"];$addtime = time();$sql = "update news set title='{$title}',keywords='{$keywords}',author='{$author}',content='{$content}',addtime={$addtime} where id = ${id}";//echo $sql; $result = mysql_query($sql);header("Location:index.php");break;}mysql_close($link); ?> </body> </html>

  統一導航欄menu.php

<ul><li><a href="index.php">瀏覽新聞</a></li><li><a href="add.php">發布新聞</a></li> </ul>

  首頁index.php

<!DOCTYPE html> <html> <head><title></title><meta charset="utf-8"> </head> <body><?php include("menu.php");?><table border="1"><thead><tr><th>id</th><th>標題</th><th>關鍵字</th><th>作者</th><th>時間</th><th>內容</th><th>操作</th></tr></thead><tbody><?phprequire("dbconfig.php");$link = @mysql_connect(HOST, USER, PASS) or die ("mysql error");mysql_select_db("newsdb", $link);$sql = "select * from news order by addtime desc";$result = mysql_query($sql, $link);while($row = mysql_fetch_assoc($result)) {echo "<tr>";echo "<td>{$row['id']}</td>";echo "<td>{$row['title']}</td>";echo "<td>{$row['keywords']}</td>";echo "<td>{$row['author']}</td>";echo "<td>".date("Y-m-d",$row['addtime'])."</td>";echo "<td>{$row['content']}</td>";echo "<td><a href='./action.php?action=del&id={$row['id']}'>刪除</a> <a href='./edit.php?id={$row['id']}'>修改</a></td>";echo "</tr>";};mysql_free_result($result);mysql_close($link);?><tr><td></td></tr></tbody></table> </body> </html>

  數據庫管理 dbconfig.php

<?phpdefine("HOST","localhost");define("USER","root");define("PASS","");define("DBNAME","newsdb"); ?>

  數據添加add.php

<!DOCTYPE html> <html> <head><title></title><meta charset="utf-8"> </head> <body><?phpinclude("menu.php"); ?><form action="action.php?action=add" method="post"><table border="1"><tbody><tr><td>標題</td><td><input type="text" name="title"></td></tr><tr><td>關鍵字</td><td><input type="text" name="keywords"></td></tr><tr><td>作者</td><td><input type="text" name="author"></td></tr><tr><td>內容</td><td><textarea name="content" rows="5" ></textarea></td></tr><tr><td colspan="2"><input type="submit" value="add"><input type="reset" value="reset"></td></tr></tbody></table></form> </body> </html>

  數據編輯edit.php

<!DOCTYPE html> <html> <head><title></title><meta charset="utf-8"> </head> <body><?phpinclude("menu.php");require("dbconfig.php");$link = @mysql_connect(HOST, USER, PASS) or die ("mysql error");mysql_select_db("newsdb", $link);$id = $_GET['id'];$sql = "select * from news where id='{$id}'";$result = mysql_query($sql, $link);if($result && mysql_num_rows($result)>0) {$news = mysql_fetch_assoc($result);}else{echo "no data";};?><form action="action.php?action=update" method="post"><table border="1"><input type="hidden" name="id" value="<?php echo $news['id'] ?>"><tbody><tr><td>標題</td><td><input type="text" name="title" value="<?php echo $news['title'] ?>"></td></tr><tr><td>關鍵字</td><td><input type="text" name="keywords" value="<?php echo $news['keywords'] ?>"></td></tr><tr><td>作者</td><td><input type="text" name="author" value="<?php echo $news['author'] ?>"></td></tr><tr><td>內容</td><td><textarea name="content" rows="5" ><?php echo $news['content'] ?></textarea></td></tr><tr><td colspan="2"><input type="submit" value="add"><input type="reset" value="reset"></td></tr></tbody></table></form> </body> </html>

  文件上傳下載系統

<!DOCTYPE html> <html> <head><title></title><meta charset="utf-8"> </head> <body> <form action="flist.php" method="post" enctype="multipart/form-data"><input type="file" name="pic" /><input type="submit" value="upload"> </form> <?phpecho "<pre>";var_dump($_FILES);$typelist = array("image/jpeg","image/jpg","image/png");@$up = $_FILES["pic"];if(!empty($up)){ switch($up["error"]) {case 1:$info = "";break;}if( !in_array($up["type"], $typelist)) {echo "error type";return ;}if( is_uploaded_file($up["tmp_name"]) ) {$upname = iconv('utf-8','gb2312',$up['name']);if(move_uploaded_file($up["tmp_name"], "./uploads/".$upname)) {echo "<br>success<br>";}else{echo "<br>error<br>";}}echo "</pre>";}?> <?php$dir = opendir("uploads");$i = 0;while($f = readdir($dir)) {if($f == "." || $f=="..") {continue;}$i++;$name=iconv("gb2312","utf-8",$f);echo "{$i}";echo "<img src='uploads/{$name}' />";echo "<br>";} ?> </body> </html>

  

  基于本地文本文件的留言管理系統

  首頁添加留言:

<!DOCTYPE html> <html> <head><meta charset="utf-8"><title></title> </head> <body><center><form action="doAdd.php" method="POST">標題:<input type="text" name="title"><br>作者:<input type="text" name="author"><br><br>內容:<textarea name="content"></textarea><br><input type="submit" value="提交"></form></center> </body> </html>

?

  添加留言的業務邏輯:

<!DOCTYPE html> <html> <head><title></title> </head> <body><?php$title = $_POST["title"];$author = $_POST["author"];$content = $_POST["content"];$ip = $_SERVER["REMOTE_ADDR"];$addtime = time();$ly = "{$title}##{$author}##{$content}##{$ip}##{$addtime}@@";$ly = $ly.file_get_contents("ly.txt");$flag = file_put_contents("ly.txt", $ly);if(!$flag) {echo "error";return;}else{header('Location: '.'./list.php');}?> </body> </html>

?

  查看留言列表:

<!DOCTYPE html> <html> <head><meta charset="utf-8"><title></title> </head> <body> <ul><?php$content = file_get_contents("ly.txt");$content = rtrim($content, "@@");$arr = explode("@@", $content);foreach($arr as $k=>$list) {echo "<li>";$con = explode("##", $list);echo "標題:{$con[0]}, 作者:{$con[1]}, 內容:{$con[2]} ,ip:{$con[3]}, 時間:".date('Y-m-d',$con[4])."<a href='del.php?id={$k}'>del</a>";echo "</li>";}?> </ul> </body> </html>

?

  刪除留言:

<!DOCTYPE html> <html> <head><meta charset="utf-8"><title></title> </head> <body><?php$id = $_GET["id"];$con = file_get_contents("ly.txt");$con = rtrim($con, "@@");$list = explode("@@", $con);unset( $list[$id] );$result = implode("@@", $list);file_put_contents("ly.txt", $result);header("Location: ./list.php");?> </body> </html>

?

<?php$arr = array(2,3,1,4); foreach( $arr as $i){echo $i."\n"; }

?

作者: NONO
出處:http://www.cnblogs.com/diligenceday/
企業網站:http://www.idrwl.com/
開源博客:http://www.github.com/sqqihao
QQ:287101329
微信:18101055830?

廈門點燃未來網絡科技有限公司, 是廈門最好的微信應用, 小程序, 微信網站, 公眾號開發公司

總結

以上是生活随笔為你收集整理的php学习实例3的全部內容,希望文章能夠幫你解決所遇到的問題。

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