首页 技术 正文
技术 2022年11月17日
0 收藏 699 点赞 4,506 浏览 2270 个字

测试截图:

PHP 简单实现MySQL数据搜索、添加数据功能 以设备管理为例

PHP 简单实现MySQL数据搜索、添加数据功能 以设备管理为例

数据库bzec ,表shebeidangan 列sb_name,sb_numandtype,sb_home,sb_usedate,sb_address,sb_updatetime,sb_remarks

html代码:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>设备档案</title>
</head>
<body><form method="post" action="s.php" name="search" />
<input name="search" type="text" value="" size="15" />
<input type="submit" value="Search" />
</form>
<br/>
<hr/>添加设备<div> <form action="sb_add.php" method="post">
设备名称:<input type="text" name="sb_name" /><br/>
编码型号:<input type="text" name="sb_numandtype" /><br/>
生产厂家:<input type="text" name="sb_home" /><br/>
启用日期:<input type="text" name="sb_usedate" /><br/>
安装位置:<input type="text" name="sb_address" /><br/>
<!--更新日期:<input type="text" name="sb_updatetime" /><br/>-->
备注 :<input type="text" name="sb_remarks" /><br/><br/>
<input type="submit" value="添加" />
</form>
</div> </body>
</html>

s.php代码:

<?php
header("Content-Type:text/html;charset=utf-8");
$con = mysql_connect("localhost","root","110");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_query("set names 'utf8'",$con);
mysql_select_db("bzec", $con); $searchs = $_POST['search']; //传递search框过来的值
$searchs= trim($searchs);
if (!$searchs)
{
echo '搜索框不能为空.';
exit;
}
$result = mysql_query("SELECT * FROM shebeidangan where sb_name like '%$searchs%'");
if (mysql_num_rows($result) < 1) echo '没有数据';while($row = mysql_fetch_array($result))
{
echo $row['sb_name'] ;
echo "<br />";
}
mysql_close($con);
?>

sb_add.php 代码如下:

<?php
$con = mysql_connect("localhost","root","110");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_query("set names 'utf8'",$con);
mysql_select_db("bzec", $con);$sb_name=$_POST['sb_name'];
$sb_numandtype=$_POST['sb_numandtype'];
$sb_home=$_POST['sb_home'];
$sb_usedate=$_POST['sb_usedate'];
$sb_address=$_POST['sb_address'];
//$sb_updatetime=$_POST['sb_updatetime'];
$sb_updatetime=date("Y-m-d G:i:s");
$sb_remarks=$_POST['sb_remarks'];//$nikename= trim($nikename);/*
if (!$nikename || !$email) //判断是否为空
{
echo '不能为空';
exit;
}
*/$sql="INSERT INTO shebeidangan (sb_name,sb_numandtype,sb_home,sb_usedate,sb_address,sb_updatetime,sb_remarks)
VALUES
('$sb_name','$sb_numandtype','$sb_home','$sb_usedate','$sb_address','$sb_updatetime','$sb_remarks')";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "ADD OK";mysql_close($con)
?>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297