php - CRUD:编辑功能不起作用它在显示所有页面中没有任何改变
问题描述
我正在尝试在 PHP 中为 CRUD 设置一个编辑方法,但是当我单击编辑按钮运行查询时,它只会将我带到显示所有页面,并且没有对其进行任何更改。
{<!doctype html>
<?php include 'db.php';
$id=$_GET['id'];
$sql="select * from users where id='$id'";
$rows=$db->query($sql);
$row=$rows->fetch_assoc();
if (isset($_GET['add'])){
$name=$_GET['name'];
$email=$_GET['email'];
$pass=$_GET['pass'];
$sql2="Update users set name='$name',email='$email',password='$pass'
where id=$id";
$db->query($sql2);
header('Location:show.php');
}
?>
<head>
<title>List</title>
</head>
<body>
<div class="container">
<div class="row" style="margin-top: 70px;">
<h1 class="text-center">All Users List</h1>
<div class="col-md-10 col-md-offset-1">
<table class="table">
<hr><br>
<form method="get" >
<div class="form-group">
<h1><?php echo $row['id'];?></h1>
<label>Name</label>
<input type="text" required name="name" value="<?php
echo $row['name'];?>" class="form-control">
<label>Email</label>
<input type="email" required name="email" value="<?php
echo $row['email'];?>" class="form-control">
<label>Password</label>
<input type="password" required name="pass" value="<?
php echo $row['password'];?>" class="form-control">
</div>
<input type="submit" name="add" value="Edit" class="btn
btn-success">
</form>
</table>
<button onclick="history.go(-1);" class="btn btn-primary">Back
</button>
</div>
</div>
</div>
</body>
</html>
所有用户表中都没有发生任何变化
解决方案
在这种情况下,您可以创建一个名为 goback() 的新函数,并在单击后退按钮时调用。
function goback(value){
window.history.go(value);
}
<button onclick="goback(-1);" class="btn btn-primary">Back </button>
推荐阅读
- javascript - 为什么从 axios 获取数据时值变化元素保持不变?
- rust - BoxOrMutRef 来自 dyn 特征的转换
- c# - 如何在 selenium c# 中断言 toast 错误消息中的文本
- reactjs - 当我不循环 setState 时,为什么我会收到最大更新深度超出错误
- c# - 使用 ProcessStartInfo 时访问被拒绝错误
- python - 读取 csv 并将单列拆分为多列
- angular - Mat-autocomplete 显示从服务器收到的上一个日期,但不是最新的。如何修复它以显示收到的最新数据?
- html - 在 Django 主页发表评论
- node.js - 没有架构的猫鼬读取
- locust - 如果任务失败则停止顺序任务