请各位老师帮忙指教

qq_41256434 2019-03-20 09:47:16
下面对已有数据修改不了。



/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- 数据库: `test`
--

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

--
-- 表的结构 `message`
--

CREATE TABLE IF NOT EXISTS `message` (
`id` tinyint(1) NOT NULL AUTO_INCREMENT,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`brand` varchar(50) NOT NULL,
`model` varchar(50) NOT NULL,
`sn` varchar(50) NOT NULL,
`fault` varchar(100) NOT NULL,
`customer` varchar(100) NOT NULL,
`tel` varchar(100) NOT NULL,
`reworkplace` varchar(100) NOT NULL,
`experiencedperson` varchar(100) NOT NULL,
`remarks` varchar(50) NOT NULL,
`status` tinyint(10) unsigned NOT NULL DEFAULT '0' COMMENT '0:未完成 1:完成',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;

--
-- 转存表中的数据 `message`
--

INSERT INTO `message` (`id`, `created_at`, `brand`, `model`, `sn`, `fault`, `customer`, `tel`, `reworkplace`, `experiencedperson`, `remarks`, `status`) VALUES
(9, '2019-03-20 05:02:27', '无奇不有', '要硬顶', '顶替琦', '枯地 ', '要夺天要', '奇才', '枯十大 ', '枯二', '顶替一概而论', 0),
(10, '2019-03-20 11:31:12', '', '', '', '', '', '', '', '', '', 0);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;



index.php

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>维修记录系统</title>
<script>
function doDel(id) {
if (confirm("确定要删除么?")) {
window.location = 'action.php?action=del&id=' + id;
}
}
</script>
</head>
<body>
<center>
<?php
include_once "menu.php";
?>
<h3>维修记录系统</h3>
<table width="600" border="1">
<tr>
<th>ID</th>
<th>日期</th>
<th>品牌</th>
<th>型号</th>
<th>序列号</th>
<th>故障</th>
<th>客户</th>
<th>联系电话</th>
<th>返修到何地</th>
<th>经手人</th>
<th>备注</th>
<th>状态</th>
</tr>
<?php
//1.连接数据库
try {
$pdo = new PDO("mysql:host=localhost;dbname=test;", "root", "168168");
} catch (PDOException $e) {
die("数据库连接失败" . $e->getMessage());
}
//2.解决中文乱码问题
$pdo->query("SET NAMES 'UTF8'");
//3.执行sql语句,并实现解析和遍历
$sql = "SELECT * FROM message ";
foreach ($pdo->query($sql) as $row)
{
echo "<tr>";
echo "<td>{$row['id']}</td>";
echo "<td>{$row['created_at']}</td>";
echo "<td>{$row['brand']}</td>";
echo "<td>{$row['model']}</td>";
echo "<td>{$row['sn']}</td>";

echo "<td>{$row['fault']}</td>";
echo "<td>{$row['customer']}</td>";
echo "<td>{$row['tel']}</td>";
echo "<td>{$row['reworkplace']}</td>";
echo "<td>{$row['experiencedperson']}</td>";
echo "<td>{$row['remarks']}</td>";
if ($row['status'] == 0)
{
echo "<td>未完成</td>";
}
else
{
echo "<td>完成</td>";
}
//echo "<td>{$row['status']}</td>";
echo "<td>
<a href='javascript:doDel({$row['id']})'>删除</a>
<a href='edit.php?id=({$row['id']})'>修改</a>
</td>";
echo "</tr>";
}

?>

</table>
</center>

</body>
</html>

menu.php

<!DOCTYPE html>
<html lang="en">
<body>
<h2>维修记录系统</h2>
<a href="index.php"> 浏览记录</a>
<a href="add.php"> 添加记录</a>
<hr>
</body>
</html>


action.php
<?php

//1.连接数据库
try{
$pdo = new PDO("mysql:host=localhost;dbname=test;","root","168168");
}catch(PDOException $e){
die("数据库连接失败".$e->getMessage());
}
//2.防止中文乱码
$pdo->query("SET NAMES 'UTF8'");
//2.通过action的值做地应操作

switch($_GET['action']){
case "add"://增加操作
//$id = $_POST['id'];
//$created_at = $_POST['data'];
$brand = $_POST['brand'];
$model = $_POST['model'];
$sn = $_POST['sn'];
$fault = $_POST['fault'];
$tel = $_POST['tel'];
$customer = $_POST['customer'];
$reworkplace = $_POST['reworkplace'];
$experiencedperson = $_POST['experiencedperson'];
$remarks = $_POST['remarks'];
$status = $_POST['status'];
$sql = "insert into message values(null,CURRENT_TIMESTAMP,'{$brand}','{$model}','{$sn}','{$fault}','{$tel}','{$customer}','{$reworkplace}','{$experiencedperson}','{$remarks}','{$status}')";
$rw = $pdo->exec($sql);
if($rw > 0){
echo "<script>alert('增加成功');window.location='index.php'</script>";
}else{
echo "<script>alert('增加失败');window.history.back();</script>";
}
break;

case "del"; //删除操作
$id = $_GET['id'];
$sql = "delete from message where id={$id}";
$pdo->exec($sql);
header("Location:index.php");
break;

case "edit":

//1.获取表单信息
//$created_at = $_POST['created_at'];
$brand = $_POST['brand'];
$model = $_POST['model'];
$sn = $_POST['sn'];
$id = $_POST['id'];
$fault = $_POST['fault'];
$tel = $_POST['tel'];
$customer = $_POST['customer'];
$reworkplace = $_POST['reworkplace'];
$experiencedperson = $_POST['experiencedperson'];
$remarks = $_POST['remarks'];
$status = $_POST['status'];
$id = $_POST['id'];
$sql = "update message set brand='{$brand}',model={$model},sn={$sn},fault={$fault},tel={$tel},customer={$customer},reworkplace={$reworkplace},experiencedperson={$experiencedperson},remarks={$remarks} ,status={$status} where id={$id}";
$rw = $pdo->exec($sql);
if($rw> 0){
echo "<script>alert('修改成功');window.location='index.php'</script>";
}else{
echo "<script>alert('增加失败');window.history.back();</script>";
}
break;
}
?>

add.php

<html>
<head>
<title>维修记录系统</title>
</head>
<body>
<center>
<?php include_once "menu.php"; ?>
<h3>增加记录信息</h3>

<form id="addstu" name="addstu" method="post" action="action.php?action=add">
<table>


<tr>
<td>品牌</td>
<td><input id="brand" name="brand" type="text"/></td>

</tr>
<tr>
<td>型号</td>
<td><input id="model" name="model" type="text"/></td>

</tr>
<tr>
<td>序列号</td>
<td><input id="sn" name="sn" type="text"/></td>

</tr>
<tr>
<td>故障</td>
<td><input id="fault" name="fault" type="text"/></td>

</tr>
<tr>
<td>客户</td>
<td><input id="customer" name="customer" type="text"/></td>

</tr>
<tr>
<td>联系电话</td>
<td><input id="tel" name="tel" type="text"/></td>

</tr>
<tr>
<td>返修到何地</td>
<td><input id="reworkplace" name="reworkplace" type="text"/></td>

</tr>
<tr>
<td>经手人</td>
<td><input id="experiencedperson" name="experiencedperson" type="text"/></td>

</tr>



<tr>
<td>备注</td>
<td><input id="remarks" name="remarks" type="text"/></td>

</tr>

<tr>
<td>状态</td>
<td><input type="radio" name="status" value="未完成"/> 未完成
<input type="radio" name="status" value="完成"/> 完成
</td>
</tr>









<tr>
<td> </td>
<td><input type="submit" value="增加"/>  
<input type="reset" value="重置"/>
</td>
</tr>
</table>

</form>
</center>
</body>
</html>

edit.php


<html>
<head>
<title>维修记录系统</title>
</head>
<body>
<center>
<?php include_once "menu.php"; ?>
<h3>增加记录信息</h3>

<form id="addstu" name="addstu" method="post" action="action.php?action=add">
<table>


<tr>
<td>品牌</td>
<td><input id="brand" name="brand" type="text"/></td>

</tr>
<tr>
<td>型号</td>
<td><input id="model" name="model" type="text"/></td>

</tr>
<tr>
<td>序列号</td>
<td><input id="sn" name="sn" type="text"/></td>

</tr>
<tr>
<td>故障</td>
<td><input id="fault" name="fault" type="text"/></td>

</tr>
<tr>
<td>客户</td>
<td><input id="customer" name="customer" type="text"/></td>

</tr>
<tr>
<td>联系电话</td>
<td><input id="tel" name="tel" type="text"/></td>

</tr>
<tr>
<td>返修到何地</td>
<td><input id="reworkplace" name="reworkplace" type="text"/></td>

</tr>
<tr>
<td>经手人</td>
<td><input id="experiencedperson" name="experiencedperson" type="text"/></td>

</tr>



<tr>
<td>备注</td>
<td><input id="remarks" name="remarks" type="text"/></td>

</tr>

<tr>
<td>状态</td>
<td><input type="radio" name="status" value="未完成"/> 未完成
<input type="radio" name="status" value="完成"/> 完成
</td>
</tr>









<tr>
<td> </td>
<td><input type="submit" value="增加"/>  
<input type="reset" value="重置"/>
</td>
</tr>
</table>

</form>
</center>
</body>
</html>

...全文
23 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧