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="更新新聞集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="更新新聞集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> <br>> <br><input type="submit" name="subs" value="搜尋"> <br>表格> <br><?php <BR>include("conn.php");//匯入連結資料庫<br>if (!empty($_GET['keys'])){ <br>$w=" title像'%".$_GET['keys']."%'"; <br>}其他{ <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($sql); <br>while($rs=mysql_fetch_array($sql); <br>while($rs=mysql_fetch_array($sql); <br>while($rs=mysql_fetch_array($sql); <br>while($rs=mysql_fetch_array($sql); <br>while($rs=mysql_fetch_array($sql); <br>while($rs=mysql_fetch_array($sql); <br>while($rs=mysql_fetch_array($sql); <br>while($rs=mysql_fetch_array($sql); $query)){ <br>?>; <br><h2>標題:<a href="view.php?id=<?php%20echo%20%24rs%5B'id'%5D%20?>"><?php echo $ rs['title' ] ?></a> <a href="edit.php?id=<?php%20echo%20%24rs%5B'id'%5D%20?>">編輯</a>||<a href="del.php?del=%20<?php%20echo%20%24rs%5B'id'%5D%20?>">刪除</a> </h2> <br>
?>
truehttp: //www.bkjia.com/PHPjc/313655.htmlTechArticle1.連結資料庫通用方法:conn.php 複製程式碼如下: ?php //第一步:連結資料庫$conn=@mysql_connect("localhost:3306","root","root")or die ("mysql連結失敗...