天天躁日日躁狠狠躁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è)置錯(cuò)誤");
?>

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)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 刺激性视频黄页 | 亚洲精品久久久久无码AV片软件 | 久久精麻豆亚洲AV国产品 | 小蝌蚪视频在线观看免费观看WWW | 久久9精品区-无套内射无码 | 欧美亚洲另类丝袜自拍动漫 | 亚洲精品高清AV在线播放 | 国产成人精品综合在线观看 | 电影 qvod| 国内精品久久久久影院老司 | 久久久久久88色偷偷 | 日韩欧美视频一区 | 欧美视频毛片在线播放 | 久久精品综合网中文字幕 | 红色机尾快播 | 换脸国产AV一区二区三区 | 国产精品.XX视频.XXTV | 日本一本二本三区免费免费高清 | 欧洲内射XXX高清 | 同居了嫂子在线观看 | 无人区乱码1区2区3区网站 | 啊叫大点声欠CAO的SAO贷 | 忘忧草在线影院WWW日本二 | 第一精品福利导福航 | 亚洲色欲国产AV精品综合 | 国产精品九九九久久九九 | 九九热这里只有精品视频免费 | 在线观看成人3d动漫入口 | 国产最新进精品视频 | 国产在线观看免费观看 | 男生插曲女生身全过程 | 出轨的妻子在线观看 | 很黄很色60分钟在线观看 | 性色少妇AV蜜臀人妻无码 | 免费a视频在线观看 | jizzxxxx18中国内地| 狠狠色狠狠色综合日日91app | 花蝴蝶高清影视视频在线播放 | 亚洲午夜久久久精品电影院 | 偷拍 自怕 亚洲 在线 | 国产一区二区三区四区五在线观看 |