php操作ACCESS(读写改)

发布时间:2011年04月11日      浏览次数:685 次
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']; /*$_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");
?>
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!