1

This is a school project I am working on, I've been debugging this for 6 hours now and getting a tad bit frustrated.

I have a page where it displays table data in an HTML input tag, at the same time, I made a query for it to be updated as you click on an update link. But so far it isn't working.

<?php
    include_once 'admindbconnect.php';

    if (isset($_GET['delete'])) {
        $query = mysqli_query($dbcon, "DELETE FROM userstable WHERE userID=".$_GET['delete']);
        header("Location: $_SERVER[PHP_SELF]");
    }

    if(isset($_POST['edit'])) {
        $query = $dbcon->query("UPDATE userstable SET username='".$_POST['viewUsername']."', userPassword='".$_POST['viewPassword']."', userEmail='".$_POST['viewEmail']."' WHERE id=".$_GET['edit']);
        mysqli_query($dbcon, $query);
        header("Location: admin.php");
    }

?>

<!DOCTYPE html>
<html>
<head>
    <title>YOU ADMIN NOW BRAH</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<center>
    <div class="fullContainer">
        <div class="header">
            <h1>DYLAN'S CONFIDENTIAL USER DATA BRAH</h1>
        </div>
        <div class="subtext">
            <h4>BE VERY SCARED BECAUSE U IN DEEP WATERS NOW BRAH</h4>
        </div>
        <br>
        <div class="adminHeader">
            <h1>DIS BE LIKE ALL DA USER DATA BRAH</h1>
            <h4><span class="blacky">BRAH DONT WORRY YOU CAN ADD DATA </span><span class="here"><a href="adminAdd.php">HERE</a></span></h4>
        </div>
        <br>
        <br>
        <div class="form">
            <table width="50%" align="center">
                <th>ID</th>
                <th>Username</th>
                <th>Password</th>
                <th>Email</th>
                <th colspan="2">Operations</th>

                <?php
                    $query = $dbcon->query("SELECT * FROM userstable");
                    while ($row=mysqli_fetch_assoc($query)) {
                ?>
                        <form action="" method="GET">
                        <tr>
                            <td>
                                <input name="viewID" value="<?php echo $row['userID']?>">
                            </td>
                            <td>
                                <input name="viewUsername" value="<?php echo $row['username']?>">
                            </td>
                            <td>
                                <input name="viewPassword" value="<?php echo $row['userPassword']?>">
                            </td>
                            <td>
                                <input name="viewEmail" value="<?php echo $row['userEmail']?>">
                            </td>
                            <td>
                                <span class="blacky"><a href="?edit=<?php echo $row['userID'];?>" onclick="return confirm('Are you sure you want to edit?');"> Update</a>
                                </span>
                            </td>
                            <td>
                                <span class="Delete"> <a href="?delete=<?php echo $row['userID'];?>" onclick="return confirm('Are you sure you want to delete?');"> Delete</a>
                                </span>
                            </td>

                <?php
                    }
                ?>
        </form>
        </div>
    </div>
</center>
</body>
</html>

Edit: Somebody marked this is a duplicate to "How to get mysqli error in different environments?" but that's not my question, my question is that why is it not updating.

0 Answers0