php增删改查demo

 时间:2024-10-14 01:05:34

1、链接数据库方法:conn.php 。代码如下:<?php$link=mysql_connect('localhost','root','tianqing')or die('数据库连接错误');mysql_select_db('studyexam',$link)or die('数据库访问错误');mysql_query("set names 'utf8'");?>

php增删改查demo

3、删除del.php代码如下:<?phpinclude("conn.php");//引入链接数据库<pre name="code" class="html"><?phpinclude("conn.php");//引入链接数据库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']?>"/>标题: <input type="text" name="title" value="<?php echo $rs['title']?>"><br>内容: <textarea rows="5" cols="50" name="con"><?php echo $rs['contents']?></textarea><br><input type="submit" name="sub" value="发表"></form></pre><br><?phpif(!empty($_GET['del'])){ $d=$_GET['del']; $sql="delete from news where id ='$d'"; } $query=mysql_query($sql); echo "删除成功"; ?><p></p><pre></pre><br>

php增删改查demo

5、查询select.php页面代码如下:<?phpinclude("conn.php");$sql="select * from entries";//entries这是数据库名词,大家自己改if($result=mysql_query($sql)){ /* $num=mysql_num_rows($result) for($i=1;$i<=$num;$i++); */ while($array=mysql_fetch_assoc($result)){ //$biaoti=$array['title']; $neirong=$array['entry']; $id=$array['entry_id']; echo "<p>{$array['title']}</p><p>$neirong</p><p><a href='edit.php?id=$id'>编辑</a>&nbsp;&nbsp; <a href='delete.php?id=$id'>删除</a></p><hr />"; }}?>

php增删改查demo
  • css如何通过class属性设置样式
  • scrollTo的使用方法
  • qq的聊天时发的语音在哪个文件夹
  • jsp如何导入一个完整的项目
  • css如何取消ul默认的圆点或序号
  • 热门搜索
    旅游管理专业课程 克拉玛依旅游 鼓浪屿旅游路线 象山影视城旅游 安康旅游景点大全 文明旅游 中国旅游地理 北京旅游图 三门峡黄河旅游节 旅游景点门票