您的位置:首页 > 编程语言 > PHP开发

php操作ACCESS(读写改)

2018-04-09 11:57 162 查看
Conn.php

---------------------------------------------------------------------------------------------------------------------------------------------------------

<?php

$conn = @new COM("ADODB.Connection") or die
("ADO连接失败!");

$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" .
realpath("include/#mydb.mdb");

$conn->Open($connstr);

//创建记录集查询

?>

Add.php

<?php

$name=$_POST['user_name'];

$content=$_POST['user_post'];

if ($name<>"" and
$content<>"")

{

       if($name="admin"
or $content="admin")

      {

              echo
"<script
language='javascript'>alert('你要干什么!');location='index.php';</script>";

       }

   include_once("include/conn.php");

   $rs =
$conn->Execute("insert into contents (name,content)
values ('$name','$content')");

   header("location:index.php");

   }

   else

   echo
"<script
language='javascript'>alert('字段不能有空!');location='index.php';</script>";

?>

Del.php

<?

session_start();

if($_SESSION['admin']=="OK")

{

include_once("include/conn.php");

$sql="delete from contents where
id=".$_GET['id'];

$rs = $conn->Execute($sql);

header("location:admin_index.php");

}

?>

Show.php

<?

session_start();

if($_SESSION['admin']=="OK")

{

include_once("include/conn.php");

$sql="select * from contents where id=".$_GET['id'];

$rs = $conn->Execute($sql);

$name=$rs->Fields['name']->Value;

$content=$rs->Fields['content']->Value;

$id=$rs->Fields['id']->Value;

?>

<form action="modify_save.php" method="post"
name="name1">

    ID :<?=$id?><input
type="hidden" name="id"
value=<?=$id?> >

    姓名:<?=$name?><br>

    留言:<textarea
name="post_contents" rows="10"
cols="50"><?=$content?></textarea>

    <input
type="submit" value="提交修改">

   </form>

<?

}

       $rs->Close();

      $conn->Close();

      $rs
= null;

      $conn
= null;

?>

Edit.php

<?

session_start();

if($_SESSION['admin']=="OK")

{

include_once("include/conn.php");

$sql="update contents set content='".$_POST['post_contents']."'
where id=".$_POST['id'];

$rs = $conn->Execute($sql);

}

header("location:admin_index.php");

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: