php數(shù)據(jù)訪問(wèn)之增刪改查操作
增刪改查操作小練習(xí),大家練練手吧



一、查看新聞頁(yè)面-----主頁(yè)面
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>查看新聞</title>
</head>
<body>
<h1>查看新聞</h1>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>id</td>
<td>title</td>
<td>author</td>
<td>source</td>
<td>content</td>
<td>date</td>
<td>update</td>
<td>delete</td>
</tr>
<?php
$db=new MySQLi("localhost","root","","mydb");
!mysqli_connect_error() or die("連接失??!");
$sql="select * from news";
$result=$db->query($sql);
$arr=$result->fetch_all();
foreach ($arr as $v)
{
echo "<tr>
<td>{$v[0]}</td>
<td>{$v[1]}</td>
<td>{$v[2]}</td>
<td>{$v[3]}</td>
<td>{$v[4]}</td>
<td>{$v[5]}</td>
<td><a href='Update.php?newsid={$v[0]}'>update</a></td>
<td><a href='Delete.php?newsid={$v[0]}'>delete</a></td>
</tr>";
}
?>
</table>
<br>
<br />
<div class="xw"><a href="xinwen.php">發(fā)布新聞</a></div>
</body>
</html>

二、發(fā)布新聞頁(yè)面-----添加內(nèi)容
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>發(fā)布新聞</title>
<style>
.xw
{
margin-top:10px;
margin-left:400px;
border:thick;
}
.a
{
float:left;
}
</style>
</head>
<body>
<h1><center>發(fā)布新聞</center></h1>
<form action="AddChu.php" method="post">
<div class="xw">標(biāo)題:<input type="text" name="title" style="width:400px"></div>
<div class="xw">作者:<input type="text" name="author"></div>
<div class="xw">來(lái)源:<input type="text" name="source"></div>
<div class="xw">內(nèi)容:
<textarea rows="10" cols="80" name="content"></textarea></div>
<div class="a"><input type="submit" value="提交" style="margin-left:600px;"></div>
<div class="a"><a href="ChaKan.php"><input type="button" value="查看" style="margin-left:6px;"></a></div>
</form>
</body>
</html>

提交內(nèi)容后的處理:
<?php
$newsid=$_POST["newsid"];
$title=$_POST["title"];
$author=$_POST["author"];
$source=$_POST["source"];
$content=$_POST["content"];
$time=date("Y-m-d",time());
$db=new MySQLi("localhost","root","","mydb");
!mysqli_connect_error() or die("聯(lián)系失敗!");
$sql="insert into news values('{$newsid}','{$title}','{$author}','{$source}','{$content}','{$time}')";
$result=$db->query($sql);
if($result)
{
header ("location:xinwen.php");
}
else
{
echo "添加新聞失??!";
}
三、刪除內(nèi)容處理
<?php
$newsid=$_GET["newsid"];
$db=new MySQLi("localhost","root","","mydb");
!mysqli_connect_error() or die("連接失敗!");
$sql="delete from news where newsid='{$newsid}'";
$result=$db->query($sql);
if($result)
{
header ("location:ChaKan.php");
}
else
{
echo "刪除數(shù)據(jù)失敗";
}
?>
四、修改新聞頁(yè)面----修改新聞內(nèi)容后提交查看
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>修改新聞</title>
<style>
.xw
{
margin-top:10px;
margin-left:400px;
border:thick;
}
.a
{
float:left;
}
</style>
</head>
<body>
<h1><center>修改新聞</center></h1>
<?php
$newsid = $_GET["newsid"];
$db = new MySQLi("localhost","root","","mydb");
$sinfo = "select * from news where newsid='{$newsid}'";
$r = $db->query($sinfo);
$arr = $r->fetch_row(); //這個(gè)人的所有信息
?>
<form action="UpdateChu.php" method="post">
<div class="xw"><input type="hidden" name="newsid" value="<?php echo $arr[0] ?>"></div>
<div class="xw">標(biāo)題:<input type="text" name="title" style="width:400px" value="<?php echo $arr[1] ?>"></div>
<div class="xw">作者:<input type="text" name="author" value="<?php echo $arr[2] ?>"></div>
<div class="xw">來(lái)源:<input type="text" name="source" value="<?php echo $arr[3] ?>"></div>
<div class="xw">內(nèi)容:
<textarea rows="10" cols="80" name="content"><?php echo $arr[4] ?></textarea></div>
<div class="a"><input type="submit" value="修改" style="margin-left:600px;"></div>
<div class="a"><a href="ChaKan.php"><input type="button" value="查看" style="margin-left:6px;"></a></div>
</form>
</body>
</html>

提交修改內(nèi)容后進(jìn)行處理:
<?php
$newsid=$_POST["newsid"];
$title=$_POST["title"];
$author=$_POST["author"];
$source=$_POST["source"];
$content=$_POST["content"];
$time=date("Y-m-d",time());
$db=new MySQLi("localhost","root","","mydb");
!mysqli_connect_error() or die("聯(lián)系失敗!");
$sql="update news set title='{$title}',author='{$author}',source='{$source}',content='{$content}',time='{$time}' where newsid='{$newsid}'";
$result=$db->query($sql);
if($result)
{
header ("location:Update.php");
}
else
{
echo "修改數(shù)據(jù)失敗!";
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)php程序設(shè)計(jì)有所幫助。
- ThinkPHP使用getlist方法實(shí)現(xiàn)數(shù)據(jù)搜索功能示例
- PHP文本數(shù)據(jù)庫(kù)的搜索方法
- PHP頁(yè)面輸出搜索后跳轉(zhuǎn)下一頁(yè)的處理方法
- PHP統(tǒng)計(jì)nginx訪問(wèn)日志中的搜索引擎抓取404鏈接頁(yè)面路徑
- php注冊(cè)審核重點(diǎn)解析(數(shù)據(jù)訪問(wèn))
- php數(shù)據(jù)訪問(wèn)之查詢關(guān)鍵字
- 實(shí)例講解php數(shù)據(jù)訪問(wèn)
- php設(shè)計(jì)模式 DAO(數(shù)據(jù)訪問(wèn)對(duì)象模式)
- php出租房數(shù)據(jù)管理及搜索頁(yè)面
相關(guān)文章
php保存任意網(wǎng)絡(luò)圖片到服務(wù)器的方法
這篇文章主要介紹了php保存任意網(wǎng)絡(luò)圖片到服務(wù)器的方法,涉及php通過(guò)curl操作遠(yuǎn)程圖片的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04
php實(shí)現(xiàn)把數(shù)組按指定的個(gè)數(shù)分隔
這篇文章主要介紹了php實(shí)現(xiàn)把數(shù)組按指定的個(gè)數(shù)分隔。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-02-02
php設(shè)計(jì)模式 Adapter(適配器模式)
將一個(gè)類的接口轉(zhuǎn)換成客戶希望的另外一個(gè)接口,使用原本不兼容的而不能在一起工作的那些類可以在一起工作2011-06-06
php抓取網(wǎng)站圖片并保存的實(shí)現(xiàn)方法
這篇文章主要介紹了php抓取網(wǎng)站圖片并保存的實(shí)現(xiàn)方法,重點(diǎn)借鑒了匹配img標(biāo)簽和其src屬性正則的寫法,封裝了一個(gè)php遠(yuǎn)程抓取圖片的類,感興趣的小伙伴們可以參考一下2015-10-10
實(shí)現(xiàn)dedecms全站URL靜態(tài)化改造的代碼
實(shí)現(xiàn)dedecms全站URL靜態(tài)化改造的代碼...2007-03-03
php 調(diào)用ffmpeg獲取視頻信息的簡(jiǎn)單實(shí)現(xiàn)
下面小編就為大家?guī)?lái)一篇php 調(diào)用ffmpeg獲取視頻信息的簡(jiǎn)單實(shí)現(xiàn)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04
PHP中Header使用的HTTP協(xié)議及常用方法小結(jié)
這篇文章主要介紹了PHP中Header使用的HTTP協(xié)議及常用方法,包含了各種錯(cuò)誤編碼類型及其含義,需要的朋友可以參考下2014-11-11
php中sprintf與printf函數(shù)用法區(qū)別解析
這篇文章主要介紹了php中sprintf與printf函數(shù)用法區(qū)別解析,需要的朋友可以參考下2014-02-02
安裝apache2.2.22配置php5.4(具體操作步驟)
本篇文章是對(duì)安裝apache2.2.22配置php5.4的具體操作步驟進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06

