0

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>
James
  • 4,644
  • 5
  • 37
  • 48
Allrounder
  • 685
  • 2
  • 9
  • 20
  • Does the operation otherwise work? As this is just a warning – James Aug 19 '18 at 09:38
  • @James If you feel that it's a possible duplicate, it's best to "flag" it as one instead of typing it out as a comment. When it gets flagged, it shows up somewhere that others may pickup on voting to close as such also. Also, if I or someone else who can hammer it with it in one go, then that too will show your name on it, rather than just the person who hammered it. Just thought I'd let you know how voting to close works. Why I think you did that would probably be that you can't "vote" to close as a duplicate. Right you are, *but* you can "flag" as a duplicate though. – Funk Forty Niner Aug 19 '18 at 11:55
  • @FunkFortyNiner yeah I already flagged for something else and changed my mind and retracted, but found a promising dupe so thought I'd make it known – James Aug 19 '18 at 11:56
  • 1
    @James Oh I see. Well I'll hammer this; it is a duplicate of it, thanks. – Funk Forty Niner Aug 19 '18 at 11:56

1 Answers1

1

try to replace that wrongful statement with something alike:

<?php echo isset($_POST["id"]) ? $_POST["id"] : ""); ?>

there won't be any $_GET["id"] unless you request with a query-string, eg. /index.php?id=420.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216