TheScruffyGuy Posted April 14, 2020 Share Posted April 14, 2020 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. 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! Quote Link to comment Share on other sites More sharing options...
Barand Posted April 14, 2020 Share Posted April 14, 2020 My advice is to rewrite it. You are repeating the same code three times. Put all the common bits in a function which you then call three times, passing a value to tell the function which table you want to output. Quote Link to comment Share on other sites More sharing options...
TheScruffyGuy Posted April 14, 2020 Author Share Posted April 14, 2020 For the way I am displaying my tables? Quote Link to comment Share on other sites More sharing options...
TheScruffyGuy Posted April 14, 2020 Author Share Posted April 14, 2020 I haven't learned about functions yet but I will give it a go Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.