php not picking up selected items to be removed
Posted: Tue Aug 24, 2010 7:46 am
I have been trying to solve this problem for a week and cannot see what I have done wrong (I am fairly new to PHP)
I am trying to make a php program that can remove items from a MySQL database. I have the form and the options. But when I click ion remove it always says:
Sorry, no high score was specified for removal.
I'm using 'localhost'.
I'm sure it is something obvious! I include both programs below:
Admin.php
<?php
require_once('appvars.php');
require_once('connectvars.php');
// Connect to the database
$dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name);
// Retrieve the score data from MySQL
$query = "SELECT * FROM gwdb ORDER by score DESC";
$data = mysqli_query($dbc, $query);
//LOOP through the array of score data, formatting as HTML
echo '<table>';
while ($row = mysqli_fetch_array($data)) {
//display score data
echo '<tr class="scorerow"><td><strong>' . $row['first_name'] . '</strong></td>';
echo '<td>' . $row['last_name'] . '</td>';
echo '<td>' . $row['score'] . '</td>';
echo '<td><a href="removescore.php?first_name= ' .$row['first_name'] . '&last_name=' . $row['last_name'] . '&score=' . $row['score'] .
' &screenshot=' . $row['screenshot'] . '">Remove</a></td></tr>';
}
echo '</table>';
mysqli_close($dbc);
?>
removescore.php
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title> Guitar wars -Remove High Socre</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h2>Guitar Wars - Remove High Score</h2>
<?php
require_once('appvars.php');
require_once('connectvars.php');
if (isset($_GET['first_name']) && isset($_GET['last_name']) && isset($_GET['score']) && isset($_GET['screeenshot'])) {
//Grab the score data from the GET
$first_name = $_GET['first_name'];
$last_name = $_GET['last_name'];
$score = $_GET['score'];
$screenshot = $_GET['screenshot'];
}
else if (isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['score'])) {
// Grab the score data from the post
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$score = $_POST['score'];
$screenshot = $_POST['screenshot'];
}
else {
echo '<P class="error">Sorry, no high score was specified for removal. </p>';
}
if (isset($_POST['submit'])) {
if ($_POST['confrim'] == 'YES' ) {
//Delete the screen shot image from the server
@unlink(GW_UPLOADPATH. $screenshot);
//Connect to the database
$dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name);
//Delete the score data from the database
$query ="DELETE_FROM gwdb WHERE first_name = $first_name LIMIT 1";
mysqli_query($dbc, $query);
mysqli_close($dbc);
//Confirm success with the user
echo '<p class="error">The high score was not removed.</p>';
}
}
else if (isset($first_name) && isset ($last_name) && isset($score) && isset($screenshot)) {
echo '<p>Are you sure you want to delete the following high score?</p>';
echo '<p><strong>First Name: </strong>' . $first_name . '<br /><strong>Last Name: </strong>' . $last_name .'<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="first_name" value =' . $firstname . '" />';
echo '<input type="hidden" name="last_name" value = '. $last_name . '" />';
echo '<input type="hidden" name="score" value = '. $score . '" />';
echo '<input type="hidden" name="screenshot" value = '. $screenshot . '">';
echo '</form>';
}
echo '<p><a href="admin.php"><< Back to admin page</a><p>';
I am trying to make a php program that can remove items from a MySQL database. I have the form and the options. But when I click ion remove it always says:
Sorry, no high score was specified for removal.
I'm using 'localhost'.
I'm sure it is something obvious! I include both programs below:
Admin.php
<?php
require_once('appvars.php');
require_once('connectvars.php');
// Connect to the database
$dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name);
// Retrieve the score data from MySQL
$query = "SELECT * FROM gwdb ORDER by score DESC";
$data = mysqli_query($dbc, $query);
//LOOP through the array of score data, formatting as HTML
echo '<table>';
while ($row = mysqli_fetch_array($data)) {
//display score data
echo '<tr class="scorerow"><td><strong>' . $row['first_name'] . '</strong></td>';
echo '<td>' . $row['last_name'] . '</td>';
echo '<td>' . $row['score'] . '</td>';
echo '<td><a href="removescore.php?first_name= ' .$row['first_name'] . '&last_name=' . $row['last_name'] . '&score=' . $row['score'] .
' &screenshot=' . $row['screenshot'] . '">Remove</a></td></tr>';
}
echo '</table>';
mysqli_close($dbc);
?>
removescore.php
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title> Guitar wars -Remove High Socre</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h2>Guitar Wars - Remove High Score</h2>
<?php
require_once('appvars.php');
require_once('connectvars.php');
if (isset($_GET['first_name']) && isset($_GET['last_name']) && isset($_GET['score']) && isset($_GET['screeenshot'])) {
//Grab the score data from the GET
$first_name = $_GET['first_name'];
$last_name = $_GET['last_name'];
$score = $_GET['score'];
$screenshot = $_GET['screenshot'];
}
else if (isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['score'])) {
// Grab the score data from the post
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$score = $_POST['score'];
$screenshot = $_POST['screenshot'];
}
else {
echo '<P class="error">Sorry, no high score was specified for removal. </p>';
}
if (isset($_POST['submit'])) {
if ($_POST['confrim'] == 'YES' ) {
//Delete the screen shot image from the server
@unlink(GW_UPLOADPATH. $screenshot);
//Connect to the database
$dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name);
//Delete the score data from the database
$query ="DELETE_FROM gwdb WHERE first_name = $first_name LIMIT 1";
mysqli_query($dbc, $query);
mysqli_close($dbc);
//Confirm success with the user
echo '<p class="error">The high score was not removed.</p>';
}
}
else if (isset($first_name) && isset ($last_name) && isset($score) && isset($screenshot)) {
echo '<p>Are you sure you want to delete the following high score?</p>';
echo '<p><strong>First Name: </strong>' . $first_name . '<br /><strong>Last Name: </strong>' . $last_name .'<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="first_name" value =' . $firstname . '" />';
echo '<input type="hidden" name="last_name" value = '. $last_name . '" />';
echo '<input type="hidden" name="score" value = '. $score . '" />';
echo '<input type="hidden" name="screenshot" value = '. $screenshot . '">';
echo '</form>';
}
echo '<p><a href="admin.php"><< Back to admin page</a><p>';