So, I'm making a trivia game--and I have a page where users can submit their own trivia questions which will later be put into games (separate part of the game that isn't too relevant here). Anyway, so prevent spam, and irrelevancy, or false submitting/trolls, I'm making a moderator approval page; this page displays individual "pending" questions that users submit. (When they submit a question, it goes into a "pending" database table called 'usertriviadata'.
Then, it displays each of the pending questions on the moderator approval page, with a submit button where a mod/admin can approve it.
Step by step this is how it works:
- The page displays (per trivia category) each individual pending question on the approval page, each one has a submit button.
- A moderator can view it, and if they want to approve it, they click the "approve" button.
- If the "approve" button is clicked, the system deletes the question from the "pending" 'usertriviadata' table, and inserts it into the 'approved' database table where I will use the data in that table for later.
The problem I'm having, and can't quite figure out how to fix--when I click the approve button, it approves ALL/ANY pending questions in that particular category. Let's say there is 3 pending questions in the "geography" category. I click approve on any of those 3 questions, and it approves all of them. Basically, the deletion and insertion (swapping data between the two database tables) works, but I want to individualize it. I've tried a few different things, but I can't quite get it right.
Any suggestions? The code is below this image (image shows the approval page to get a general idea of what it looks like when there are multiple pending questions):
[enter image description here][1]
<div class="categories">
<h3>Geography</h3>
<?php
$sql = "SELECT questionID, category, uploaderUsername, question, correctAnswer, answerTwo, answerThree, answerFour FROM usertriviadata WHERE category='geography'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$questionID = $row['questionID'];
$category = $row['category'];
$uploaderUsername = $row['uploaderUsername'];
$question = $row['question'];
$correctAnswer = $row['correctAnswer'];
$answerTwo = $row['answerTwo'];
$answerThree = $row['answerThree'];
$answerFour = $row['answerFour'];
echo "<div class='individuals'><p>Question ID: $questionID</p> <p>Category: $category</p> <p>Uploader Username: $uploaderUsername</p> <p>Question: $question</p> <p>Correct Answer: $correctAnswer</p> <p>Answer 2: $answerTwo</p> <p>Answer 3: $answerThree</p> <p>Answer 4: $answerFour</p> <form action='' method='GET'><input type='submit' name='submit' value='Approve'/></form> </div> ";
if (isset($_GET["submit"])) {
// Move question to approved table
$sql = "INSERT INTO approved (category, uploaderUsername, question, correctAnswer, answerTwo, answerThree, answerFour)
VALUES ('$category', '$uploaderUsername', '$question', '$correctAnswer', '$answerTwo', '$answerThree', '$answerFour')";
// Error Handles
if ($conn->query($sql) === TRUE) {
echo "<p class='green'>Question approved.</p>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// Delete question from pending/usertriviadata table
$sql = "DELETE FROM usertriviadata WHERE questionID='$questionID'";
if ($conn->query($sql) === TRUE) {
echo "<p class='green'>Question removed from pending/usertriviadata database table. Please wait 5 seconds before approving another post.</p>";
echo "<meta http-equiv='refresh' content='5; URL=../triviaApproval/moderatorApproval' />";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
}
} else {
echo "No posts need approved here.";
}
?>
</div>```
If you want the CSS as well, it is here:
```html {
background-color: #AC6A6C;
font-family: "Trirong", serif;
color: #DEF706;
text-align: center;
}
.option-a {
text-align: center;
display: inline;
background-color: gray;
color: #DEF706;
font-size: 125%;
width: 100px;
padding: 0.5%;
text-decoration: none;
}
.option-a:hover {
cursor: pointer;
background-color: #4E4E4D;
}
.option-a:focus {
padding: 0.3%;
background-color: blue;
}
.individuals {
padding: 1%;
display: inline-block;
border: 1px solid;
}
.green {
color: green;
}
```[enter image description here][2]