In my website I have three databases: new tasks, pending tasks, and competed tasks. To move data from new tasks to pending tasks works but when I try to move the data from pending tasks to completed tasks I get the following error:
Notice: Undefined index: id in C:\wamp64\www\Test\mark-complete.php on line 66 Call Stack #TimeMemoryFunctionLocation 10.0008247288{main}( )...\mark-complete.php:0 "/>
Line 66 is the following code:
<input type="hidden" name="id" value="<?php echo trim($_GET["id"]); ?>"/>
Here is my full code for moving the data from pending to complete:
<?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>