国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

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

2024-05-04 23:12:50
字體:
來源:轉載
供稿:網友
1.鏈接數據庫通用方法:conn.php

復制代碼 代碼如下:


<?php
//第一步:鏈接數據庫
$conn=@mysql_connect("localhost:3306","root","root")or die ("mysql鏈接失敗");
//第二步: 選擇指定的數據庫,設置字符集
@mysql_select_db("php_blog",$conn) or die ("db鏈接失敗".mysql_error());
mysql_query('SET NAMES UTF8')or die ("字符集設置錯誤");
?>


2.增加 add.php

復制代碼 代碼如下:


<?php
include("conn.php");//引入鏈接數據庫
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">
標題: <input type="text"><br>
內容: <textarea rows="5" cols="50"></textarea><br>
<input type="submit" value="發表">
</form>


3.刪除del.php

復制代碼 代碼如下:


<?php
include("conn.php");//引入鏈接數據庫<pre><?php
include("conn.php");//引入鏈接數據庫
if(!empty ($_GET['id'])){
$sql="select * from news whereid']."'";
$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 where limit 1 ";
mysql_query($sql);
echo "<script> alert('更新成功'); location.href='index.php'</script>";
echo"更新成功";
}
?>
<form action="edit.php" method="post">
<input type="hidden" value="<?php echo $rs['id']?>"/>
標題: <input type="text" value="<?php echo $rs['title']?>"><br>
內容: <textarea rows="5" cols="50"><?php echo $rs['contents']?></textarea><br>
<input type="submit" value="發表">
</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><?php
include("conn.php");//引入鏈接數據庫
if(!empty ($_GET['id'])){
$sql="select * from news whereid']."'";
$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 where limit 1 ";
mysql_query($sql);
echo "<script> alert('更新成功'); location.href='index.php'</script>";
echo"更新成功";
}
?>
<form action="edit.php" method="post">
<input type="hidden" value="<?php echo $rs['id']?>"/>
標題: <input type="text" value="<?php echo $rs['title']?>"><br>
內容: <textarea rows="5" cols="50"><?php echo $rs['contents']?></textarea><br>
<input type="submit" value="發表">
</form></pre><br>
5.查,列表頁面<pre><a href="add.php">添加內容</a>
<hr>
<hr>
<form>
<input type="text" />
<input type="submit" value="搜索"/>
</form>
<?php
include("conn.php");//引入鏈接數據庫
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>標題:<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>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武安市| 泰兴市| 重庆市| 新绛县| 靖安县| 东宁县| 博爱县| 卢湾区| 定襄县| 旅游| 鹤壁市| 台东市| 汶上县| 上思县| 吴旗县| 蒲江县| 怀集县| 江源县| 伊宁市| 彝良县| 榆树市| 特克斯县| 巩义市| 镇远县| 柳河县| 濉溪县| 夏津县| 邛崃市| 平乡县| 东阳市| 高密市| 赤壁市| 武定县| 科技| 蓝田县| 阿坝县| 甘谷县| 额济纳旗| 富川| 苍梧县| 白城市|