PHP MySQL 增查删改
来源:互联网 发布:.us域名查询 编辑:程序博客网 时间:2024/06/01 09:17
丑的一批,但还能看。
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SELECT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="#" method="post" name="form1">
查询关键字:
<input type="text" name="txt_keyword" id="txt_keyword" />
<input type="submit" name="Submit" id="Submit" value="搜索" onclick=" return check(form1)" />
</form>
<script language="javascript">
function check(form1)
{
if(form1.txt_keyword.value=="")
{
alert("请输入关键字!");
form1.txt_keyword.focus();
return false;
}
form1.submit();
}
</script>
<?php
$link=mysql_connect("localhost","root","a3141592654")or die("数据库服务器连接失败!".mysql_error());
mysql_select_db("msphp",$link);
mysql_query("set names utf-8");
$sql=mysql_query("select * from tb_affiche");
$info=mysql_fetch_array($sql);
if($_POST['Submit']=="搜索")
{
$keyword=$_POST['txt_keyword'];
$sql=mysql_query("select * from tb_affiche where title like '%$keyword%' or content like '%$keyword%'");
$info=mysql_fetch_array($sql);
}
if($info==false)
{
//echo "检索信息失败";
echo "<script> alert('检索信息失败!'); window.location.hre='#'; </script>";
}
else
{
//echo "检索信息成功";
echo "<script> alert('检索信息成功!'); window.location.href='#'; </script>";
}
do{
echo $info[id]." ";
echo $info[title]."<br>";
echo $info[content];
echo "<a href='update.php?id=".$info[id]."&title=".$info[title]."&content=".$info[content]."'>编辑</a>";
echo "<a href='delete.php?id=".$info[id]."&title=".$info[title]."&content=".$info[content]."'>删除</a><br/><br/>";
}while($info=mysql_fetch_array($sql));
?>
</body>
</html>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
INSERT
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="#" method="post" name="form1">
公告主题:
<input type="text" name="txt_title" id="txt_title" /><br />
公告内容:
<textarea name="txt_content" id="txt_content" role="10" cols="100" ></textarea><br />
<input type="submit" name="Submit" id="Submit" value="保存" onclick="return check(form1)" />
<input type="reset" name="Reset" id="Reset" value="重置" />
</form>
<script language="javascript">
function check(form1)
{
if(form1.txt_title.value=="")
{
alert("请输入公告标题");
form1.txt_title.focus();
return false;
}
if(form1.txt_content.value=="")
{
alert("请输入公告标题");
form1.txt_content.focus();
return false;
}
form1.submit();
}
</script>
<?php
$link=mysql_connect("localhost","root","a3141592654")or die("数据服务器连接失败!".mysql_error());
mysql_select_db("msphp",$link)or die("数据库连接失败!".mysql_error());
mysql_query("set names utf-8");
date_default_timezone_set("RPC");
if($_POST['Submit']=="保存")
{
$title=$_POST['txt_title'];
$content=$_POST['txt_content'];
$createtime=date("Y-m-d H:i:s");
$sql=mysql_query("insert into tb_affiche(title,content,createtime)values('$title','$content','$createtime')");
if($sql)
{
echo "<script> alert('信息添加成功!'); window.location.href='#'; <script/>";
}
else
{
echo "<script> alert('信息添加失败!'); window.location.href='#';<script/>";
}
}
mysql_close();
?>
</body>
</html>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
$id=$_GET['id'];
$title = $_GET['title'];
$content = $_GET['content'];
?>
<form action="#" name="form1" method="post">
公告主题:
<input type="text" name="txt_title" id="txt_title" value="<?php echo $title;?>" />
<input type="hidden" name="id" value="<?php echo $id;?>" />
<br />
公告内容:
<textarea name="txt_content" id="txt_content"><?php echo $content;?></textarea><br />
<input type="submit" name="Submit" id="Submit" value="修改" onclick="return check(form1)" />
<input type="reset" name="Reset" id="Reset" value="重置" />
</form>
<script language="javascript">
function check(form1)
{
if(form1.txt_title.value=="")
{
alert("请输入公告标题");
form1.txt_title.focus();
return false;
}
if(form1.txt_content.value=="")
{
alert("请输入公告内容");
form1.txt_content.focus();
return false;
}
form1.submit();
}
</script>
<?php
$link=mysql_connect("localhost","root","a3141592654")or die("数据库服务器连接失败!".mysql_error());
mysql_select_db("msphp",$link);
mysql_query("set names utf-8");
if($_POST['Submit']=="修改")
{
$id=$_POST['id'];
$title=$_POST['txt_title'];
$content=$_POST['txt_content'];
$sql=mysql_query("update tb_affiche set title='".$title."',content='".$content."' where id='".$id."'");
if($sql==false)
{
//echo "检索信息失败";
echo "<script> alert('修改信息失败!'); history.back(); window.location.href='select2.php'; </script>";
}
else
{
//echo "检索信息成功";
echo "<script> alert('修改信息成功!'); history.back(); window.location.href='select2.php'; </script>";
}
}
?>
</body>
</html>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DELECT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
$id=$_GET['id'];
$title=$_GET['title'];
$content=$_GET['content'];
?>
<form name="form1" action="#" method="post">
公告主题:
<input type="text" name="txt_title" id="txt_title" value="<?php echo $title;?>" />
<input type="hidden" name="id" value="<?php echo $id;?>" />
<br />
公告内容:
<textarea name="txt_content"><?php echo $content;?></textarea>
<br />
<input type="submit" name="Submit" value="删除" />
</form>
<?php
$link=mysql_connect("localhost","root","a3141592654")or die("数据库服务器连接失败!".mysql_error());
mysql_select_db("msphp",$link)or die("数据库连接失败!".mysql_error());
mysql_query("set names utf-8");
if($_POST['Submit']=="删除")
{
$id=$_POST['id'];
$title=$_POST['txt_title'];
$content=$_POST['txt_content'];
$sql=mysql_query("delete from tb_affiche where id='".$id."'");
if($sql==false)
{
echo "<script> alert('信息删除失败!');history.back();window.location.href='select2.php'</script>";
}
else
{
echo "<script> alert('信息删除成功!');history.back();window.location.href='select2.php'</script>";
}
}
mysql_close();
?>
</body>
</html>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
未附加数据库。
- PHP MySQL 增查删改
- mysql增查删改
- 判断php操作mysql(添删改查)是否成功
- 【java源码】jdbc实现增查删改<Mysql>
- Java对MySQL中的数据实现增查删改
- PHP 操作 mongoDB 之添删改查
- MySQL是什么玩意儿(三)查删改
- 简单模板链表。增查删改
- PHP+SQLServer2005+Apache/系统DSN配置+ODBC查插删改
- MYSQL数据库添删改查—操作过程记录
- Repeater实现删改查
- discuz中快速建立增查删改界面:第1步,用小猫统计在mysql中建立国土面积表
- 简单的数据库操作 增 删改 查 Java编程
- 一个实例掌握linq to XML增查删改
- 使用dom4j实现xml的增查删改
- ssm框架下对数据库表的增查删改
- ssm框架下对数据库表的增查删改
- 双链表的插删改查
- sql执行顺序
- adb常用命令
- springmvc 中自定义拦截器
- HTML5新增的标签
- 我的第一次java考试题目
- PHP MySQL 增查删改
- php实现哈希表
- Merge Two Sorted Lists
- NOIP模拟(11.02)T4 赌博游戏
- 11.2考试爆炸记
- opencv----霍夫(Hough)变换:霍夫线变换,霍夫圆变换
- 画圆带动态边框圆中间显示百分比跟随边框动
- HDU 1430 DFS + 康托展开 + 映射处理 +预处理!
- Flatten Binary Tree to Linked List