欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php數(shù)據(jù)訪問之增刪改查操作

 更新時(shí)間:2016年05月09日 11:36:12   作者:陌上初薰  
這篇文章主要為大家詳細(xì)介紹了php數(shù)據(jù)訪問之增刪改查操作的相關(guān)資料,感興趣的小伙伴們可以參考一下

增刪改查操作小練習(xí),大家練練手吧

一、查看新聞頁(yè)面-----主頁(yè)面

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>查看新聞</title>
</head>
 
<body>
<h1>查看新聞</h1>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
  <td>id</td>
  <td>title</td>
  <td>author</td>
  <td>source</td>
   <td>content</td>
  <td>date</td>
  <td>update</td>
  <td>delete</td>
</tr>
<?php
$db=new MySQLi("localhost","root","","mydb");
!mysqli_connect_error() or die("連接失??!");
$sql="select * from news";
$result=$db->query($sql);
$arr=$result->fetch_all();
foreach ($arr as $v)
{
  echo "<tr>
  <td>{$v[0]}</td>
  <td>{$v[1]}</td>
  <td>{$v[2]}</td>
  <td>{$v[3]}</td>
  <td>{$v[4]}</td>
  <td>{$v[5]}</td>
  <td><a href='Update.php?newsid={$v[0]}'>update</a></td>
  <td><a href='Delete.php?newsid={$v[0]}'>delete</a></td>
   
  </tr>";
  }
 
?>
</table>
<br>
<br />
<div class="xw"><a href="xinwen.php">發(fā)布新聞</a></div>
 
</body>
</html>

  

二、發(fā)布新聞頁(yè)面-----添加內(nèi)容

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>發(fā)布新聞</title>
<style>
.xw
{
   
  margin-top:10px;
  margin-left:400px;
  border:thick; 
  }
.a
{
  float:left;
   
  }
 
</style>
 
</head>
 
<body>
<h1><center>發(fā)布新聞</center></h1>
 
<form action="AddChu.php" method="post">
<div class="xw">標(biāo)題:<input type="text" name="title" style="width:400px"></div>
<div class="xw">作者:<input type="text" name="author"></div>
<div class="xw">來(lái)源:<input type="text" name="source"></div>
<div class="xw">內(nèi)容:
<textarea rows="10" cols="80" name="content"></textarea></div>
 
<div class="a"><input type="submit" value="提交" style="margin-left:600px;"></div>
<div class="a"><a href="ChaKan.php"><input type="button" value="查看" style="margin-left:6px;"></a></div>
 
</form>
 
 
</body>
</html>

  

提交內(nèi)容后的處理:

<?php
$newsid=$_POST["newsid"];
$title=$_POST["title"];
$author=$_POST["author"];
$source=$_POST["source"];
$content=$_POST["content"];
$time=date("Y-m-d",time());
 
$db=new MySQLi("localhost","root","","mydb");
!mysqli_connect_error() or die("聯(lián)系失敗!");
$sql="insert into news values('{$newsid}','{$title}','{$author}','{$source}','{$content}','{$time}')";
$result=$db->query($sql);
if($result)
{
  header ("location:xinwen.php");
  }
else
{
  echo "添加新聞失敗!";
  }

三、刪除內(nèi)容處理

<?php
$newsid=$_GET["newsid"];
$db=new MySQLi("localhost","root","","mydb");
!mysqli_connect_error() or die("連接失敗!");
$sql="delete from news where newsid='{$newsid}'";
$result=$db->query($sql);
if($result)
{
  header ("location:ChaKan.php");
  }
else
{
  echo "刪除數(shù)據(jù)失敗";
  }
?>
  

四、修改新聞頁(yè)面----修改新聞內(nèi)容后提交查看

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>修改新聞</title>
<style>
.xw
{
   
  margin-top:10px;
  margin-left:400px;
  border:thick; 
  }
   
.a
{
  float:left;
   
  }
 
</style>
</head>
 
<body>
<h1><center>修改新聞</center></h1>
<?php
$newsid = $_GET["newsid"];
$db = new MySQLi("localhost","root","","mydb");
$sinfo = "select * from news where newsid='{$newsid}'";
$r = $db->query($sinfo);
$arr = $r->fetch_row(); //這個(gè)人的所有信息
?>
 
<form action="UpdateChu.php" method="post">
<div class="xw"><input type="hidden" name="newsid" value="<?php echo $arr[0] ?>"></div>
<div class="xw">標(biāo)題:<input type="text" name="title" style="width:400px" value="<?php echo $arr[1] ?>"></div>
<div class="xw">作者:<input type="text" name="author" value="<?php echo $arr[2] ?>"></div>
<div class="xw">來(lái)源:<input type="text" name="source" value="<?php echo $arr[3] ?>"></div>
<div class="xw">內(nèi)容:
<textarea rows="10" cols="80" name="content"><?php echo $arr[4] ?></textarea></div>
 
<div class="a"><input type="submit" value="修改" style="margin-left:600px;"></div>
<div class="a"><a href="ChaKan.php"><input type="button" value="查看" style="margin-left:6px;"></a></div>
 
</form>
 
</body>
</html>  

  

提交修改內(nèi)容后進(jìn)行處理:

<?php
$newsid=$_POST["newsid"];
$title=$_POST["title"];
$author=$_POST["author"];
$source=$_POST["source"];
$content=$_POST["content"];
$time=date("Y-m-d",time());

$db=new MySQLi("localhost","root","","mydb");
!mysqli_connect_error() or die("聯(lián)系失敗!");
$sql="update news set title='{$title}',author='{$author}',source='{$source}',content='{$content}',time='{$time}' where newsid='{$newsid}'";
$result=$db->query($sql);
if($result)
{
  header ("location:Update.php");
  }
else
{
  echo "修改數(shù)據(jù)失敗!";
  }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)php程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • 解析php5配置使用pdo

    解析php5配置使用pdo

    本篇文章是對(duì)php5配置使用pdo的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-07-07
  • PHP緩存工具XCache安裝與使用方法詳解

    PHP緩存工具XCache安裝與使用方法詳解

    這篇文章主要介紹了PHP緩存工具XCache安裝與使用方法,較為詳細(xì)的分析了緩存工具XCache在Windows及Linux平臺(tái)安裝與Xcache操作封裝類實(shí)例,需要的朋友可以參考下
    2018-04-04
  • php需登錄的文件上傳管理系統(tǒng)

    php需登錄的文件上傳管理系統(tǒng)

    這篇文章主要介紹了php需登錄的文件上傳管理系統(tǒng),文章中跟大家分享了一個(gè)很完整的php代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2015-10-10
  • PHP使用stream_context_create()模擬POST/GET請(qǐng)求的方法

    PHP使用stream_context_create()模擬POST/GET請(qǐng)求的方法

    這篇文章主要介紹了PHP使用stream_context_create()模擬POST/GET請(qǐng)求的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了stream_context_create模擬POST/GET請(qǐng)求的原理,使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2016-04-04
  • PHP單元測(cè)試配置與使用方法詳解

    PHP單元測(cè)試配置與使用方法詳解

    這篇文章主要介紹了PHP單元測(cè)試配置與使用方法,結(jié)合實(shí)例形式詳細(xì)分析了PHP單元測(cè)試的具體安裝、配置、使用方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2019-12-12
  • PHP中imagick函數(shù)的中文解釋

    PHP中imagick函數(shù)的中文解釋

    這篇文章主要介紹了PHP中imagick函數(shù)的中文解釋,ImageMagick是一套功能強(qiáng)大、穩(wěn)定而且免費(fèi)的工具集和開發(fā)包,可以用來(lái)讀、寫和處理超過185種基本格式的圖片文件,包括流行的TIFF、JPEG、GIF、PNG、PDF以及PhotoCD等格式,需要的朋友可以參考下
    2015-01-01
  • PHP查詢MySQL大量數(shù)據(jù)的時(shí)候內(nèi)存占用分析

    PHP查詢MySQL大量數(shù)據(jù)的時(shí)候內(nèi)存占用分析

    這篇文章主要是從原理, 手冊(cè)和源碼分析在PHP中查詢MySQL返回大量結(jié)果時(shí), 內(nèi)存占用的問題, 同時(shí)對(duì)使用MySQL C API也有涉及.
    2011-07-07
  • php判斷一個(gè)數(shù)組是否為有序的方法

    php判斷一個(gè)數(shù)組是否為有序的方法

    這篇文章主要介紹了php判斷一個(gè)數(shù)組是否為有序的方法,涉及php操作數(shù)組遍歷的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-03-03
  • php xfocus防注入資料

    php xfocus防注入資料

    個(gè)很重要的問題,我隨便看了下關(guān)于php安全的資料,并不是很 多,至少比asp少多了,呵呵,于是就想寫點(diǎn)東西,來(lái)防止這些可能注入出現(xiàn)的情況。
    2008-04-04
  • jQuery獲取json后使用zy_tmpl生成下拉菜單

    jQuery獲取json后使用zy_tmpl生成下拉菜單

    這篇文章主要介紹了我開發(fā)過程中使用jQuery獲取json后使用zy_tmpl生成下拉菜單的實(shí)例,雖然是第一次寫關(guān)于AppCan開發(fā)的內(nèi)容,有需要的小伙伴可以參考下。
    2015-03-03

最新評(píng)論