php - 在mysql和php中将数据从一个数据库移动到另一个数据库时出错
问题描述
在我的网站中,我有三个数据库:新任务、待处理任务和已完成任务。要将数据从新任务移动到待处理任务,但是当我尝试将数据从待处理任务移动到已完成任务时,我收到以下错误:
注意:未定义索引:第 66 行 C:\wamp64\www\Test\mark-complete.php 中的 id 调用堆栈 #TimeMemoryFunctionLocation 10.0008247288{main}( )...\mark-complete.php:0 "/>
第 66 行是以下代码:
<input type="hidden" name="id" value="<?php echo trim($_GET["id"]); ?>"/>
这是我将数据从待处理移动到完成的完整代码:
<?php
if(isset($_POST["id"]) && !empty($_POST["id"])){
require_once 'config.php';
$param_id = trim($_POST["id"]);
$sql1 = "INSERT INTO completetask SELECT * FROM pendingtask WHERE id = ? ";
$sql2 = "DELETE FROM pendingtask WHERE id = ? ";
if($stmt = mysqli_prepare($link, $sql1)){
mysqli_stmt_bind_param($stmt, "i", $param_id);
if(mysqli_stmt_execute($stmt)){
// Record inserted successfully. Close statement and delete record
from table_1
mysqli_stmt_close($stmt);
if($stmt = mysqli_prepare($link, $sql2)){
mysqli_stmt_bind_param($stmt, "i", $param_id);
if(mysqli_stmt_execute($stmt)){
// Close statement
mysqli_stmt_close($stmt);
// Records deleted successfully. Redirect to landing page
header("location: notifications.php");
exit();
}else{
echo "Oops! Something went wrong. Please try again later.";
}
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close connection
mysqli_close($link);
} else{
// Check existence of id parameter
if(empty(trim($_GET["id"]))){
// URL doesn't contain id parameter. Redirect to error page
header("location: error.php");
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>View Record</title>
<link href="assets/css/bootstrap.css" rel="stylesheet" />
<style type="text/css">
.wrapper{
width: 500px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1>Move Task to Completed Tasks</h1>
</div>
<form action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="alert alert-danger fade in">
<input type="hidden" name="id" value="<?php echo
trim($_GET["id"]); ?>"/>
<p>Are you sure you want to move to Completed Tasks?
</p><br>
<p>
<input type="submit" value="Yes" class="btn btn-
danger">
<a href="notifications.php" class="btn btn-
default">No</a>
</p>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
解决方案
尝试用类似的东西替换那个错误的陈述:
<?php echo isset($_POST["id"]) ? $_POST["id"] : ""); ?>
$_GET["id"]
除非您使用查询字符串请求,否则不会有任何内容,例如。/index.php?id=420
.
推荐阅读
- python - 问题在 PyCharm 中运行 Python 3.7 以执行 Twitter Bot(通过 Tweepy)
- javascript - 具有不透明边缘的实心圆环 - THREE.js
- java - 我正在尝试将扫描仪输入用于 for 循环,该循环计算从最小值到最大值的数字并在终端中显示数字
- java - MySQL Connector/J 驱动程序是否实现 JdbcRowSet 接口?
- omnet++ - 如何使用 setDoubleValue() 在 Omnet++ 中更改参数运行时
- dart - 如何修复向特定Web服务器发出http请求的flutter web http错误
- r - 我可以在不终止 R 会话的情况下停止正在进行的操作吗?
- python - 如何在循环数据框时将数据添加到绘图
- mysql - 按年龄查找数据库中每个人的计数
- firebase - Flutter FirebaseDatabase 运行事务崩溃