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>
<?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>
<a href="add.php">添加内容</a> <br><hr> <br><hr> <br>