Skip to content
Advertisement

Updating and deleting from a data table, warning undefined array key

I have been following a lesson on how to make an admin page. I got all the information out of my database to a table on the page. I have an update button and when I change the information and press the button I receive this error: Warning: undefined array key “WebID” in ..Update.php on line 3

From my search online everyone is trying to change the code so that if array key does not exist: return null. I tried that and the error does not appear no more, but the table does not change.

Any thoughts?

This is the code:

<?php
require_once("DB/DB.php");
$SearchQueryParameter = $_GET["WebID"];

if (isset($_POST["Update"])) {

    $Ename = $_POST["Ename"];
    $Eid = $_POST["Eid"];
    $Erank = $_POST["Erank"];
    $Eemail = $_POST["Eemail"];
    $Edate = $_POST["Edate"];
    $Epassword = $_POST["Epassword"];
    $Specialisms = $_POST["Specialisms"];

    global $ConnectingDB;
    $sql ="UPDATE emp_data SET Ename='$Ename', Eid='$Eid', Erank='$Erank', Eemail='$Eemail', Edate='$Edate', Epassword='$Epassword', 
    Specialisms='$Specialisms' WHERE WebID='$SearchQueryParameter'";

    $Execute = $ConnectingDB->query($sql);
    if ($Execute) {
        echo '<script>window.open("adminpage.php?WebID=Recored Updated","_self")</script>';
    }
}

?>

<?php

<?php
global $ConnectingDB;
$sql = "SELECT * FROM emp_data WHERE WebID='$SearchQueryParameter'";
$stmt = $ConnectingDB->query($sql);
while ($DataRows = $stmt->fetch()) {
    $WebID = $DataRows["WebID"];
    $Ename = $DataRows["Ename"];
    $Eid = $DataRows["Eid"];
    $Erank = $DataRows["Erank"];
    $Eemail = $DataRows["Eemail"];
    $Edate = $DataRows["Edate"];
    $Epassword = $DataRows["Epassword"];
    $Specialisms = $DataRows["Specialisms"];
}
?>

Html file used to update:

<form id="UpdateForm"  method="post" action="Update.php?WebID<?php echo $SearchQueryParameter; ?>">

<div class="form-group">
<button type="submit" name="Update" class="form-control-submit-button">Update</button>
</div>

Advertisement

Answer

you have to write the form action like this.. you missed the = sign

action="Update.php?WebID=<?php echo $SearchQueryParameter; ?>"
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement