天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

php增刪改查示例自己寫的demo

1.鏈接數(shù)據(jù)庫通用方法:conn.php
復(fù)制代碼 代碼如下:
<?php
//第一步:鏈接數(shù)據(jù)庫
$conn=@mysql_connect("localhost:3306","root","root")or die ("mysql鏈接失敗");
//第二步: 選擇指定的數(shù)據(jù)庫,設(shè)置字符集
@mysql_select_db("php_blog",$conn) or die ("db鏈接失敗".mysql_error());
mysql_query('SET NAMES UTF8')or die ("字符集設(shè)置錯誤");
?>

2.增加 add.php
復(fù)制代碼 代碼如下:
<?php
include("conn.php");//引入鏈接數(shù)據(jù)庫
if(!empty($_POST['sub'])){
$title=$_POST['title'];
$con=$_POST['con'];
echo $sql="insert into news(id,title,dates,contents) value (null,'$title',now(),'$con')" ;
mysql_query($sql);
echo"插入成功";
}
?>
<form action="add.php" method="post">
標(biāo)題: <input type="text" name="title"><br>
內(nèi)容: <textarea rows="5" cols="50" name="con"></textarea><br>
<input type="submit" name="sub" value="發(fā)表">
</form>

3.刪除del.php
復(fù)制代碼 代碼如下:
<?php
include("conn.php");//引入鏈接數(shù)據(jù)庫<pre name="code" class="html"><?php
include("conn.php");//引入鏈接數(shù)據(jù)庫
if(!empty ($_GET['id'])){
$sql="select * from news where id='".$_GET['id']."'";
$query=mysql_query($sql);
$rs=mysql_fetch_array($query);
}
if(!empty($_POST['sub'])){
$title=$_POST['title'];
$con=$_POST['con'];
$hid=$_POST['hid'];
$sql="update news set title='$title',contents='$con' where id='$hid' limit 1 ";
mysql_query($sql);
echo "<script> alert('更新成功'); location.href='index.php'</script>";
echo"更新成功";
}
?>
<form action="edit.php" method="post">
<input type="hidden" name="hid" value="<?php echo $rs['id']?>"/>
標(biāo)題: <input type="text" name="title" value="<?php echo $rs['title']?>"><br>
內(nèi)容: <textarea rows="5" cols="50" name="con"><?php echo $rs['contents']?></textarea><br>
<input type="submit" name="sub" value="發(fā)表">
</form></pre><br>
if(!empty($_GET['del'])){ $d=$_GET['del']; $sql="delete from news where id ='$d'"; } $query=mysql_query($sql); echo "刪除成功"; ?><p></p>
<pre></pre>
<br>
4,改 edit.php頁面
<p></p>
<p><br>
</p>
<p></p><pre name="code" class="html"><?php
include("conn.php");//引入鏈接數(shù)據(jù)庫
if(!empty ($_GET['id'])){
$sql="select * from news where id='".$_GET['id']."'";
$query=mysql_query($sql);
$rs=mysql_fetch_array($query);
}
if(!empty($_POST['sub'])){
$title=$_POST['title'];
$con=$_POST['con'];
$hid=$_POST['hid'];
$sql="update news set title='$title',contents='$con' where id='$hid' limit 1 ";
mysql_query($sql);
echo "<script> alert('更新成功'); location.href='index.php'</script>";
echo"更新成功";
}
?>
<form action="edit.php" method="post">
<input type="hidden" name="hid" value="<?php echo $rs['id']?>"/>
標(biāo)題: <input type="text" name="title" value="<?php echo $rs['title']?>"><br>
內(nèi)容: <textarea rows="5" cols="50" name="con"><?php echo $rs['contents']?></textarea><br>
<input type="submit" name="sub" value="發(fā)表">
</form></pre><br>
5.查,列表頁面<pre name="code" class="html"><a href="add.php">添加內(nèi)容</a>
<hr>
<hr>
<form>
<input type="text" name="keys" />
<input type="submit" name="subs" value="搜索"/>
</form>
<?php
include("conn.php");//引入鏈接數(shù)據(jù)庫
if(!empty($_GET['keys'])){
$w=" title like '%".$_GET['keys']."%'";
}else{
$w=1;
}
$sql="select * from news where $w order by id desc";
$query=mysql_query($sql);
while($rs=mysql_fetch_array($query)){
?>
<h2>標(biāo)題:<a href="view.php?id=<?php echo $rs['id'] ?>"><?php echo $rs['title'] ?></a> <a href="edit.php?id=<?php echo $rs['id'] ?>">編輯</a>||<a href="del.php?del=<?php echo $rs['id'] ?>">刪除</a></h2>
<li><?php echo $rs['dates'] ?></li>
<p><?php echo $rs['contents'] ?></p>
<hr>
<?php
}
?>
</pre><br>
<p></p>
<p><br>
</p>

php技術(shù)php增刪改查示例自己寫的demo,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 777精品久无码人妻蜜桃 | 亚洲偷自拍精品视频在线观看 | 99精品国产自在自线 | 欧美乱码伦视频免费66网 | 久草高清在线 | 国产盗摄一区二区三区 | 新香蕉少妇视频网站 | 99久久久免费精品国产 | 久啪久久全部视频在线 | 丝袜诱惑qvod | 色综合久久88色综合天天提莫 | 野草在线视频完整视频 | 国产在线观看免费观看 | 老子午夜伦不卡电影院 | 20岁αsrian男同志免费 | 国产女人与黑人在线播放 | 樱花草在线观看影院 | 神马电影我不卡4k手机在线观看 | 制服国产欧美亚洲日韩 | 国产精品自产拍在线观看中文 | 国产乱国产乱老熟300部视频 | 国产精品青草久久福利不卡 | 亚洲AV久久久噜噜噜久久 | 好紧好湿太硬了我太爽了小说 | 伊人亚洲综合青草青草久热 | 国产免费午夜高清 | 亚洲理论在线a中文字幕 | 日本亚洲欧洲免费旡码 | 无套暴躁白丝秘书 | 国产在线aaa片一区二区99 | 成人小视频免费在线观看 | 午夜影院老司机 | 亚洲精品有码在线观看 | 伊人久久国产精品 | 99精品视频 | 色人阁影视 | 亚洲精品青青草原avav久久qv | 久久五月综合婷婷中文云霸高清 | 国产成人精品男人的天堂网站 | 亚洲AV久久婷婷蜜臀无码不卡 | 黑粗硬大欧美在线视频 |