java web 实现的增删改查(php+mysql+apache)

实现的完整代码见超链接的压缩包:

压缩包

具体代码如下:

mysql代码:

 /*
Navicat MySQL Data Transfer

Source Server         : APP
Source Server Version : 50722
Source Host           : 127.0.0.1:3306
Source Database       : itcast

Target Server Type    : MYSQL
Target Server Version : 50722
File Encoding         : 65001

Date: 2018-07-22 10:16:11
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for customer
-- ----------------------------
DROP TABLE IF EXISTS `customer`;
CREATE TABLE `customer` (
  `id` int(11) NOT NULL,
  `customerNo` varchar(16) NOT NULL COMMENT '瀹㈡埛缂栧彿',
  `customerName` varchar(100) DEFAULT NULL COMMENT '瀹㈡埛鍚嶇О',
  `linkMan` varchar(200) DEFAULT NULL COMMENT '娉曚汉浠h〃',
  `mobilePhone` varchar(200) DEFAULT NULL COMMENT '鎵嬫満鍙',
  `pigSource` varchar(16) DEFAULT NULL COMMENT '浜у湴鍚嶇О',
  `carNumber` varchar(32) DEFAULT NULL COMMENT '閰嶉?杞﹀彿',
  `farm` varchar(200) DEFAULT NULL COMMENT '鍏绘畺鍦哄悕绉',
  `quarantineUnit` varchar(32) DEFAULT NULL COMMENT '妫?柅鍙戣瘉鍗',
  `regID` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;

-- ----------------------------
-- Records of customer
-- ----------------------------
INSERT INTO `customer` VALUES ('1019', '3710827010005', '孔学荣', '孔学荣', '06315710936', '山东省威海市经济技术开发区', '鲁K39207', '孔学荣养殖场', '威海市动物卫生监督所', '371000300005054');
INSERT INTO `customer` VALUES ('1020', '3710827010006', '张焕文', '张焕文', '06315783937', '山东省威海市荣成市', '鲁KD2031', '张焕文猪肉店', '荣成市动物防疫监督所宁津分所', '371000300000621');
INSERT INTO `customer` VALUES ('1021', '3710827010007', '朱初勋', '朱初勋', '06315963171', '山东省威海市荣成市', '鲁KZCX', '朱初勋猪肉店', '荣成市动物防疫监督所宁津分所', '371000300002449');
INSERT INTO `customer` VALUES ('1022', '3710827010008', '巩子贵', '巩子贵', '06315301882', '山东省威海市荣成市', '鲁KGZG', '巩子贵猪肉店', '荣成市动物防疫监督所东山分所', '371000300003554');
INSERT INTO `customer` VALUES ('1023', '3710827010009', '刘忠棉', '刘忠棉', '06315925176', '山东省威海市荣成市', '鲁K8175D', '刘忠棉养殖场', '荣成市动物防疫监督所宁津分所', '371000300003595');
INSERT INTO `customer` VALUES ('1024', '3710827010010', '许波', '许波', '06315180636', '山东省威海市荣成市', '鲁K39207', '许波养殖场', '荣成市动物防疫监督所宁津分所', '371000300004090');
INSERT INTO `customer` VALUES ('1025', '3710827010011', '张常利', '张常利', '06315921181', '山东省威海市荣成市', '鲁K8175D', '张常利养殖场', '荣成市动物防疫监督所东山分所', '371000200009103');
INSERT INTO `customer` VALUES ('1026', '3710827010012', '张启强', '张启强', '06315323092', '山东省威海市荣成市', '鲁KZQQ', '张启强猪肉店', '荣成市动物防疫监督所宁津分所', '371000300002393');
INSERT INTO `customer` VALUES ('1027', '3710827010013', '曹付泉', '曹付泉', '06315992279', '山东省威海市荣成市', '鲁KCFQ', '曹付泉养殖场', '荣成市动物防疫监督所俚岛分所', '371000300002301');
INSERT INTO `customer` VALUES ('1028', '3710827010014', '曲秀连', '曲秀连', '06315901988', '山东省威海市荣成市', '鲁K39213', '曲秀连养殖场', '荣成市动物防疫监督所龙须分所', '371000300002289');
INSERT INTO `customer` VALUES ('1029', '3710827010015', '刘科', '刘科', '06315922182', '山东省威海市荣成市', '鲁K8175D', '刘科养殖场', '荣成市动物防疫监督所宁津分所', '371021018806213');
INSERT INTO `customer` VALUES ('1030', '3710827010016', '林治永', '林治永', '06318545339', '山东省威海市荣成市', '鲁K39213', '林治永养殖场', '荣成市动物防疫监督所宁津分所', '371000300002963');
INSERT INTO `customer` VALUES ('1031', '3710827010017', '闫海峰', '闫海峰', '06315961700', '山东省威海市荣成市', '鲁K8175D', '闫海峰养殖场', '荣成市动物防疫监督所崂山分所', '371000300003128');
INSERT INTO `customer` VALUES ('1032', '3710827010018', '董虎男', '董虎男', '06315373826', '山东省威海市荣成市', '鲁KDHN', '董虎男养殖场', '荣成市动物防疫监督所宁津分所', '371000300002818');
INSERT INTO `customer` VALUES ('1033', '3710827010019', '冯志野', '冯志野', '06315982475', '山东省威海市荣成市', '鲁KFZY', '冯志野养殖场', '荣成市动物防疫监督所宁津分所', '371000300002256');
INSERT INTO `customer` VALUES ('1034', '3710827010020', '马丰良', '马丰良', '06315385219', '山东省威海市荣成市', '鲁K39207', '马丰良养殖场', '荣成市动物防疫监督所宁津分所', '371000300001333');
INSERT INTO `customer` VALUES ('1035', '3710827010021', '邹英娜', '邹英娜', '06315328323', '山东省威海市荣成市', '鲁K8175D', '邹英娜养殖场', '荣成市动物防疫监督所城西分所', '371000119020345');

php代码:

SelectStuUpdate.php

<?php
header("content-type:text/html;charset=utf-8");
require "DbFunct/PublicFunction.class.php";
$db = new MySQLDB(array("dbname"=>"itcast","port"=>"3306"));
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$strSql = "select * from customer where id=$id";
$stuData = $db->FetchRow($strSql);
require "SelectStuEdit.php";
?>

SelectStuSaveAdd.php

<?php
header("content-type:text/html;charset=utf-8");
require "DbFunct/PublicFunction.class.php";
$id = $_POST['id'];
$db = new MySQLDB(array("dbname"=>"itcast","port"=>"3306"));
$values = array();
$fields = array('id','customerNo','customerName','linkMan','mobilePhone','pigSource','carNumber','farm','quarantineUnit','regID');
foreach($fields as $k => $v){
    $data = isset($_POST[$v]) ? $_POST[$v] : '';
    if($data == '') die($v.'字段不能为空');
    $fields[$k] = "$v";
    $values[] = "'$data'";
}
$fields = implode(',',$fields);
$values = implode(',',$values);
$strSql = "insert into customer($fields) values($values);"; 
$res = $db->query($strSql);
if($res){
    header("Location: ./SelectStuInfo.php");
}else{
    die('信息添加失败');
}
?>

SelectStuSave.php

<?php
header("content-type:text/html;charset=utf-8");
require "DbFunct/PublicFunction.class.php";
$id = $_POST['id'];
$db = new MySQLDB(array("dbname"=>"itcast","port"=>"3306"));
$update = array();
$fields = array('id','customerNo','customerName','linkMan','mobilePhone','pigSource','carNumber','farm','quarantineUnit','regID');
foreach($fields as $v){
    $data = isset($_POST[$v]) ? $_POST[$v] : '';
    $update[] = "$v = '$data'";
}
$update_str = implode(',',$update);
$strSql = "update customer set $update_str where id=$id"; 
$res = $db->query($strSql);
if($res){
    header("Location: ./SelectStuInfo.php");
}else{
    die('信息添加失败');
}
?>

SelectStuReset1.php

<?php
header("content-type:text/html;charset=utf-8");
require "DbFunct/PublicFunction.class.php";
$db = new MySQLDB(array("dbname"=>"itcast","port"=>"3306"));
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$strSql = "select * from customer where id=$id";
$stuData = $db->FetchRow($strSql);
$stuData['customerNo'] = null;
$stuData['customerName'] = null;
$stuData['linkMan'] = null;
$stuData['mobilePhone'] = null;
$stuData['pigSource'] = null;
$stuData['carNumber'] = null;
$stuData['farm'] = null;
$stuData['quarantineUnit'] = null;
$stuData['regID'] = null;
$stuData['id'] = $id;
require "SelectStuEdit.php";
?>

SelectStuReset.php

<?php
require "SelectStuAdd.php";
?>

SelectStuInfo.php

<?php
header("content-type:text/html;charset=utf-8");
require "DbFunct/PublicFunction.class.php";
$db = new MySQLDB(array("dbname"=>"itcast","port"=>"3306"));
$strSql = "Select * from customer";
$stuData = $db->FetchAll($strSql);
include "SelectStuHtml.php";
?>

SelectStuHtml.php

<html>
<head>
    <meta charset="utf-8">
    <title>客户信息表</title>
    <link rel="stylesheet" type="text/css" href="CSS/DbApp.css">
</head>
<body class="dbCustomer">
    <table>
    <tr><td colspan="11"><h1>客户信息表</h1></td></tr>
    <tr><td colspan="11"><a href="SelectStuAdd.php"><h2>添加客户</h2></a></td></tr>
        <tr><td>序号</td><td>客户编号</td><td>超市名</td><td>联系人</td><td>电话</td><td>地址</td><td>车牌号</td><td>农场</td><td>监督所</td><td>身份证号</td><td>操作</td></tr>
        <?php foreach($stuData as $item){ ?>
            <tr>
                <td><?php echo $item["id"];?></td>
                <td><?php echo $item["customerNo"];?></td>
                <td><?php echo $item["customerName"];?></td>
                <td><?php echo $item["linkMan"];?></td>
                <td><?php echo $item["mobilePhone"];?></td>
                <td><?php echo $item["pigSource"];?></td>
                <td><?php echo $item["carNumber"];?></td>
                <td><?php echo $item["farm"];?></td>
                <td><?php echo $item["quarantineUnit"];?></td>
                <td><?php echo $item["regID"];?></td>
                <td><a href="SelectStuUpdate.php?id=<?php echo $item["id"];?>"><img src="./image/edt.gif">修改</a>
                <a href="SelectStuDelete.php?id=<?php echo $item["id"];?>"><img src="./image/del.gif">删除</a></td>
            </tr>
        <?php } ?>
    </table>
</body>
</html>

SelectStuEdit.php

<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="CSS/DbEdit.css">
<title>修改客户信息</title>
</head>
<body>
    <div class="box">
        <h1>修改客户信息</h1>
        <form method="post" action="./SelectStuSave.php">
            <table>
                <tr><th>序号</th><td><input type="text" name="id" value="<?php echo $stuData['id']?>"></td></tr>
                <tr><th>客户编号</th><td><input type="text" name="customerNo" value="<?php echo $stuData['customerNo']?>"></td></tr>
                <tr><th>超市名</th><td><input type="text" name="customerName" value="<?php echo $stuData['customerName']?>"></td></tr>
                <tr><th>联系人</th><td><input type="text" name="linkMan" value="<?php echo $stuData['linkMan']?>"></td></tr>
                <tr><th>电话</th><td><input type="text" name="mobilePhone" value="<?php echo $stuData['mobilePhone']?>"></td></tr>
                <tr><th>地址</th><td><input type="text" name="pigSource" value="<?php echo $stuData['pigSource']?>"></td></tr>
                <tr><th>车牌号</th><td><input type="text" name="carNumber" value="<?php echo $stuData['carNumber']?>"></td></tr>
                <tr><th>农场</th><td><input type="text" name="farm" value="<?php echo $stuData['farm']?>"></td></tr>
                <tr><th>监督所</th><td><input type="text" name="quarantineUnit" value="<?php echo $stuData['quarantineUnit']?>"></td></tr>
                <tr><th>身份证号</th><td><input type="text" name="regID" value="<?php echo $stuData['regID']?>"></td></tr>
                <tr><td colspan="2">
                    <input type="submit" value="保存数据">
                    <a href="SelectStuReset1.php?id=<?php echo $stuData['id'];?>"><input type="button" value="重填数据"></a>
                </td></tr>
            </table>
        </form>
    </div>
</body>
</html>

SelectStuDelete.php

 <?php
header("content-type:text/html;charset=utf-8");
require "DbFunct/PublicFunction.class.php";
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$db = new MySQLDB(array("dbname"=>"itcast","port"=>"3306"));
$strSql = "delete from customer where id = $id;"; 
$res = $db->query($strSql);
if($res){
    header("Location: ./SelectStuInfo.php");
}else{
    die('信息添加失败');
}
?>

SelectStuAdd.php

<html>
 <head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="CSS/DbEdit.css">
<title>添加客户信息</title>
</head>
<body>
<div class="box">
    <h1>添加客户信息</h1>
    <form method="post" action="./SelectStuSaveAdd.php">
        <table>
            <tr><th>序号</th><td><input type="text" name="id" value=""></td></tr>
            <tr><th>客户编号</th><td><input type="text" name="customerNo" value=""></td></tr>
            <tr><th>超市名</th><td><input type="text" name="customerName" value=""></td></tr>
            <tr><th>联系人</th><td><input type="text" name="linkMan" value=""></td></tr>
            <tr><th>电话</th><td><input type="text" name="mobilePhone" value=""></td></tr>
            <tr><th>地址</th><td><input type="text" name="pigSource" value=""></td></tr>
            <tr><th>车牌号</th><td><input type="text" name="carNumber" value=""></td></tr>
            <tr><th>农场</th><td><input type="text" name="farm" value=""></td></tr>
            <tr><th>监督所</th><td><input type="text" name="quarantineUnit" value=""></td></tr>
            <tr><th>身份证号</th><td><input type="text" name="regID" value=""></td></tr>
            <tr><td colspan="2">
                <input type="submit" value="添加数据">
                <a href="SelectStuReset.php?id=<?php echo $stuData['id'];?>"><input type="reset" value="重填数据"></a>
            </td></tr>
        </table>
    </form>
</div>
</body>
</html>

css样式、公共函数见压缩包

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值