Jump to content

Problem with Edit and Deletes on differ Tables


TheScruffyGuy

Recommended Posts

Hello, I will try to explain this in as much detail as I can. I am probably making a simple mistake but I have gone through the code multiple times and can't figure it out.

I have 3 HTML Site tables, pending, accepted and denied applications. I have accept, deny, and delete buttons on all the tables for each row. I could probably do with out the accept and deny buttons on the last two HTML Site tables, but in the case an admin making a mistake and clicking the wrong button. I don't want the admin to have to delete the app and have the user fill out a new one. User experience and all that.

My problem: The last two HTML Site tables, Accept and Denied, the three buttons do not function but in Pending they do. I don't remember assigning those functions to one table and looked thought the code and didn't see any place I did it is only looking for id at the displayed row. Enough of my jabbering. Here is what I am working with.

 

admin_panel.thumb.png.9db945dfcecc815dd9357eaeb1ec6c4f.png

    

Here is the code, I have done for the deletes and edits to the application status.

//DELETE APPLICATION

if(isset($_POST['delete'])) {

    $to_change = mysqli_real_escape_string($conn, $_POST['to_change']);



    $sql = "DELETE FROM apps WHERE id = $to_change";



    if(mysqli_query($conn, $sql)) {

        $feedback['delete'] = '<div class="green white-text alert-box">Success the user deleted from list.</div>';

        header('Location: admin.php');

    } else {

        $feedback['ui_feedback'] = '<div class="red white-text alert-box">Connection Error</div>';

    }

} else {

    $feedback['ui_feedback'] = '<div class="red white-text alert-box">Connection Error</div>';

}



//UPDATE APPLICATION STATUS TO ACCEPT

if(isset($_POST['accept'])) {

    $to_change = mysqli_real_escape_string($conn, $_POST['to_change']);

    //QUERY DB

    mysqli_query($conn, "UPDATE apps SET app_status='Accepted' WHERE id = $to_change");

    $feedback['accept'] = '<div class="green white-text alert-box">Success, the user was accepted.</div>';

    header('Location: admin.php');

} else {

    $feedback['ui_feedback'] = '<div class="red white-text alert-box">Connection Error</div>';

}



//UPDATE APPLICATION STATUS TO DENIED

if(isset($_POST['denied'])) {

    $to_change = mysqli_real_escape_string($conn, $_POST['to_change']);

    //QUERY DB

    mysqli_query($conn, "UPDATE apps SET app_status='Denied' WHERE id = $to_change");

    $feedback['denied'] = '<div class="green white-text alert-box">Success, the user was denied.</div>';

    header('Location: admin.php');

} else {

    $feedback['ui_feedback'] = '<div class="red white-text alert-box">Connection Error</div>';

}

I know the $feedback doesn't work I wanted to see it worked and it didn't I will research that later.

<!-- NEW APPLICATIONS -->
            <div id="new_apps" class="container white container-style">
                <h4 class="blue-text text-darken-3">New Applications</h4>
                <div class="table-responsive">
                <table class="highlight centered row">
                    <thead>
                        <tr class="">
                            <th class="blue-text text-darken-3">ID</th>
                            <th class="blue-text text-darken-3">Name</th>
                            <th class="blue-text text-darken-3">Email</th>
                            <th class="blue-text text-darken-3">Discord</th>
                            <th class="blue-text text-darken-3">Steam Hex ID</th>
                            <th class="blue-text text-darken-3">DOB</th>
                            <th class="blue-text text-darken-3">Department</th>
                            <th class="blue-text text-darken-3">Date Applied</th>
                            <th class="blue-text text-darken-3">Status</th>
                            <th class="blue-text text-darken-3">Actions</th>
                        </tr>
                        <tbody class="">
<?php if($pending): ?>
<?php foreach($pending as $pend): ?>
                                    <tr>
                                        <td><?php echo $pend['id']; ?></td>
                                        <td><?php echo $pend['first_name'] . " " . $pend['last_name']; ?></td>
                                        <td><?php echo $pend['email']; ?></td>
                                        <td><?php echo $pend['discord_name']; ?></td>
                                        <td><?php echo $pend['steam_hex']; ?></td>
                                        <td><?php echo $pend['dob']; ?></td>
                                        <td><?php echo $pend['dept_select']; ?></td>
                                        <td><?php echo $pend['created_at']; ?></td>
                                        <td><?php echo $pend['app_status']; ?></td>
                                        <td>
                                            <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
                                                <input type="hidden" name="to_change"  value="<?php echo $pend['id']; ?>">
                                                <button type="submit" name="accept" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Accept"><i class="material-icons green-text text-darken-3">check_circle</i></button>
                                                <button type="submit" name="denied" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Deny"><i class="material-icons yellow-text text-darken-3">not_interested</i></button>
                                                <button type="submit" name="delete" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Delete"><i class="material-icons red-text text-darken-3">delete</i></button>
                                            </form>
                                        </td>
                                    </tr>
                            </tbody>
<?php endforeach; ?>
<?php else: ?>
                <div class="blue darken-3 white-text table-empty-box">There are no applications</div>
<?php endif; ?>
                        </thead>
                    </table>
            </div>
        </div>
<!-- ACCEPTED APPLICATIONS-->
                <div id="accepted_apps" class="container white container-style">
                    <h4 class="blue-text text-darken-3">Accepted Applications</h4>
                    <div class="table-responsive">
                    <table class="highlight centered row">
                        <thead>
                        <tr class="">
                            <th class="blue-text text-darken-3">ID</th>
                            <th class="blue-text text-darken-3">Name</th>
                            <th class="blue-text text-darken-3">Email</th>
                            <th class="blue-text text-darken-3">Discord</th>
                            <th class="blue-text text-darken-3">Steam Hex ID</th>
                            <th class="blue-text text-darken-3">DOB</th>
                            <th class="blue-text text-darken-3">Department</th>
                            <th class="blue-text text-darken-3">Date Applied</th>
                            <th class="blue-text text-darken-3">Status</th>
                            <th class="blue-text text-darken-3">Actions</th>
                        </tr>
                            <tbody class="">
<?php if($accepted): ?>
<?php foreach($accepted as $accept): ?>
                                    <tr>
                                        <td><?php echo $accept['id']; ?></td>
                                        <td><?php echo $accept['first_name'] ." " . $accept['last_name']; ?></td>
                                        <td><?php echo $accept['email']; ?></td>
                                        <td><?php echo $accept['discord_name']; ?></td>
                                        <td><?php echo $accept['steam_hex']; ?></td>
                                        <td><?php echo $accept['dob']; ?></td>
                                        <td><?php echo $accept['dept_select']; ?></td>
                                        <td><?php echo $accept['created_at']; ?></td>
                                        <td><?php echo $accept['app_status']; ?></td>
                                        <td>
                                            <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
                                                <input type="hidden" name="to_change"  value="<?php echo $accept['id']; ?>">
                                                <a type="submit" name="accept" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Accept"><i class="material-icons green-text text-darken-3">check_circle</i></a>
                                                <a type="submit" name="denied" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Deny"><i class="material-icons yellow-text text-darken-3">not_interested</i></a>
                                                <a type="submit" name="delete" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Delete"><i class="material-icons red-text text-darken-3">delete</i></a>
                                            </form>
                                        </td>
                                    </tr>
<?php endforeach; ?>
<?php else: ?>
                                <div class="blue darken-3 white-text table-empty-box">There are no applications</div>
<?php endif; ?>
                            </tbody>
                        </thead>
                    </table>
                    </div>
                </div>
<!-- deniedED APPLICATIONS -->
            <div id="denieded_apps" class="container white container-style">
                <h4 class="blue-text text-darken-3">Denied Applications</h4>
                <div class="table-responsive">
                <table class="highlight centered row">
                    <thead>
                    <tr class="">
                            <th class="blue-text text-darken-3">ID</th>
                            <th class="blue-text text-darken-3">Name</th>
                            <th class="blue-text text-darken-3">Email</th>
                            <th class="blue-text text-darken-3">Discord</th>
                            <th class="blue-text text-darken-3">Steam Hex ID</th>
                            <th class="blue-text text-darken-3">DOB</th>
                            <th class="blue-text text-darken-3">Department</th>
                            <th class="blue-text text-darken-3">Date Applied</th>
                            <th class="blue-text text-darken-3">Status</th>
                            <th class="blue-text text-darken-3">Actions</th>
                        </tr>
                        <tbody class="">
<?php if($denied): ?>
<?php foreach($denied as $deny): ?>
                                <tr>
                                    <td><?php echo $deny['id']; ?></td>
                                    <td><?php echo $deny['first_name'] ." " . $deny['last_name']; ?></td>
                                    <td><?php echo $deny['email']; ?></td>
                                    <td><?php echo $deny['discord_name']; ?></td>
                                    <td><?php echo $deny['steam_hex']; ?></td>
                                    <td><?php echo $deny['dob']; ?></td>
                                    <td><?php echo $deny['dept_select']; ?></td>
                                    <td><?php echo $deny['created_at']; ?></td>
                                    <td><?php echo $deny['app_status']; ?></td>
                                    <td>
                                        <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
                                            <input type="hidden" name="to_change"  value="<?php echo $deny['id']; ?>">
                                            <a type="submit" name="accept" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Accept"><i class="material-icons green-text text-darken-3">check_circle</i></a>
                                            <a type="submit" name="denied" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Deny"><i class="material-icons yellow-text text-darken-3">not_interested</i></a>
                                            <a type="submit" name="delete" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Delete"><i class="material-icons red-text text-darken-3">delete</i></a>
                                        </form>
                                    </td>
                                </tr>
<?php endforeach; ?>
<?php else: ?>
                                <div class="blue darken-3 white-text table-empty-box">There are no applications</div>
<?php endif; ?>
                        </tbody>
                    </thead>
                </table>
                </div>
            </div>

 

Any help would be amazing even if you tell me to look at a line lol

I am getting back into php after only doing it for a few weeks after switching to firebase,  just coming back to what works and not having limits. 

Thank you for taking the time to read this!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.