1.链接数据库通用方法:conn.php
<?php <BR>include("conn.php");//引入链接数据库 <BR>if(!empty ($_GET['id'])){ <BR>$sql="select * from news where id='".$_GET['id']."'"; <BR>$query=mysql_query($sql); <BR>$rs=mysql_fetch_array($query); <BR>} <BR>if(!empty($_POST['sub'])){ <BR>$title=$_POST['title']; <BR>$con=$_POST['con']; <BR>$hid=$_POST['hid']; <BR>$sql="update news set title='$title',contents='$con' where id='$hid' limit 1 "; <BR>mysql_query($sql); <BR>echo "<script> alert('更新成功'); location.href='index.php'</script>"; <BR>echo"更新成功"; <BR>} <BR>?> <BR><form action="edit.php" method="post"> <BR><input type="hidden" name="hid" value="<?php echo $rs['id']?>"/> <BR>标题: <input type="text" name="title" value="<?php echo $rs['title']?>"><br> <BR>内容: <textarea rows="5" cols="50" name="con"><?php echo $rs['contents']?></textarea><br> <BR><input type="submit" name="sub" value="发表"> <BR></form><?php <BR>include("conn.php");//引入链接数据库 <BR>if(!empty ($_GET['id'])){ <BR>$sql="select * from news where id='".$_GET['id']."'"; <BR>$query=mysql_query($sql); <BR>$rs=mysql_fetch_array($query); <BR>} <BR>if(!empty($_POST['sub'])){ <BR>$title=$_POST['title']; <BR>$con=$_POST['con']; <BR>$hid=$_POST['hid']; <BR>$sql="update news set title='$title',contents='$con' where id='$hid' limit 1 "; <BR>mysql_query($sql); <BR>echo "<script> alert('更新成功'); location.href='index.php'</script>"; <BR>echo"更新成功"; <BR>} <BR>?> <BR><form action="edit.php" method="post"> <BR><input type="hidden" name="hid" value="<?php echo $rs['id']?>"/> <BR>标题: <input type="text" name="title" value="<?php echo $rs['title']?>"><br> <BR>内容: <textarea rows="5" cols="50" name="con"><?php echo $rs['contents']?></textarea><br> <BR><input type="submit" name="sub" value="发表"> <BR></form><a href="add.php">添加内容</a> <BR><hr> <BR><hr> <BR><form> <BR><input type="text" name="keys" /> <BR><input type="submit" name="subs" value="搜索"/> <BR></form> <BR><?php <BR>include("conn.php");//引入链接数据库 <BR>if(!empty($_GET['keys'])){ <BR>$w=" title like '%".$_GET['keys']."%'"; <BR>}else{ <BR>$w=1; <BR>} <BR>$sql="select * from news where $w order by id desc"; <BR>$query=mysql_query($sql); <BR>while($rs=mysql_fetch_array($query)){ <BR>?> <BR><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> <BR><li><?php echo $rs['dates'] ?></li> <BR><p><?php echo $rs['contents'] ?></p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/2140">
<img src="https://img.php.cn/upload/ai_manual/000/000/000/175680088878918.png" alt="芦笋演示">
</a>
<div class="aritcle_card_info">
<a href="/ai/2140">芦笋演示</a>
<p>一键出成片的录屏演示软件,专为制作产品演示、教学课程和使用教程而设计。</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="芦笋演示">
<span>34</span>
</div>
</div>
<a href="/ai/2140" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="芦笋演示">
</a>
</div>
<p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p> <BR><hr> <BR><?php <BR>} <BR>?> <BR>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号