*sigh
Admin Page
[code=php]
<?php
require_once(‘dbc.php’);
require_once(‘apps.php’);
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(‘Problem Connecting’ . mysqli_connect_error());
mysqli_select_db($dbc, DB_NAME);
$query = “SELECT * FROM guitarwars ORDER BY score DESC, date ASC”;
$data = mysqli_query($dbc, $query) or die(‘Problem Querying’ . mysqli_connect_error());;
echo ‘<table cellpadding=”5″>’;
while($row = mysqli_fetch_array($data))
{ echo ‘<tr><td><strong>’ . $row[‘name’] . ‘</strong></td>’;
echo ‘<td>’ . $row[‘date’] . ‘</td>’;
echo ‘<td>’ . $row[‘score’] . ‘</td>’;
echo ‘<td><a href=”removescore.php?id=’.$row[‘id’].’&date=’.$row[‘date’].’&name=’.$row[‘name’].’&score=’.$row[‘score’].’&screenshot=’.$row[‘screenshot’].'”>Remove</a></td></tr>’;
}
echo ‘</table>’;
mysqli_close($dbc);
?>
Remove Score Script:
[code=php]
<?php
require_once(‘dbc.php’);
require_once(‘apps.php’);
if(isset($_GET[‘id’]) && isset($_GET[‘date’]) && isset($_GET[‘name’]) && isset($_GET[‘score’]) && isset($_GET[‘screenshot’]))
{ //grab score data
$id = $_GET[‘id’];
$date = $_GET[‘date’];
$name = $_GET[‘name’];
$score = $_GET[‘score’];
$screenshot = $_GET[‘screenshot’];
}
elseif(isset($_POST[‘id’]) && isset($_POST[‘name’]) && isset($_POST[‘score’]))
{ //grab the post data
$id = $_POST[‘id’];
$name = $_POST[‘name’];
$score = $_POST[‘score’];
}
else { echo ‘<p class=”error”>Sorry, no score was specified for removal.</p>’; }
if(isset($_POST[‘submit’]))
{ if($_POST[‘confirm’] == ‘Yes’)
{ //delete the screenshot image from file
@unlink(GW_UPLOADPATH . $screenshot);
//connect to database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(‘Problem Connecting’ . mysqli_connect_error());
mysqli_select_db($dbc, DB_NAME);
//delete score data from db
$query = “DELETE FROM guitarwars WHERE id = $id LIMIT = 1”;
mysqli_query($dbc, $query);
mysqli_close($dbc);
//confirmation
echo ‘<p>The high score of ‘ .$score . ‘ for ‘ . $name . ‘ was succesfully deleted.</p>’;
}
else { echo ‘<p class=”error”>The high score was not removed.</p>’; }
}
elseif(isset($id) && isset($name) && isset($date) && isset($score))
{
echo ‘<p>Are you sure that you want to delete the following score?</p>’;
echo ‘<p><strong>Name: </strong>’ . $name . ‘<br /><strong>Date: </strong>’ . $date . ‘<br /><strong>Score: </strong>’ . $score . ‘</p>’;
echo ‘<form method=”post” action=”removescore.php”>’;
echo ‘<input type=”radio” name=”confirm” value=”Yes” /> Yes ‘;
echo ‘<input type=”radio” name=”confirm” value=”No” checked=”checked” /> No <br />’;
echo ‘<input type=”submit” value=”Submit” name=”submit” />’;
echo ‘<input type=”hidden” name=”id” value=”‘ . $id . ‘” />’;
echo ‘<input type=”hidden” name=”name” value=”‘ . $name . ‘” />’;
echo ‘<input type=”hidden” name=”score” value=”‘ . $score . ‘” />’;
echo ‘</form>’;
}
echo ‘<p><a href=”admin.php”><< Back to Admin Page</a></p>’;
?>
It all runs and works all dandy, except, even though confirmation that a row was removed, it wasn’t. Coz when you click the admin page link. The score is still there…