21,887
社区成员
发帖
与我相关
我的任务
分享
//index.php
<meta />
<title>Guitar Wars - High Scores</title>
<link/>
<h2>Guitar Wars - High Scores</h2>
<p>Welcome, Guitar Warrior, do you have what it takes to crack the high score list? If so, just <a href="addscore.php">add your own score</a>.</p>
<hr />
<?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 guitarwars";
$data = mysqli_query($dbc, $query);
// Loop through the array of score data, formatting it as HTML
echo '<table>';
while ($row = mysqli_fetch_array($data)) {
// Display the score data
echo '<tr><td class="scoreinfo">';
echo '<span class="score">' . $row['score'] . '</span><br />';
echo '<strong>Name:</strong> ' . $row['name'] . '<br />'; //上传的名字
echo '<strong>Date:</strong> ' . $row['data'] . '</td>'; //上传的日期
if (is_file(@$GW_UPLOADPATH . $row['screenshot']) && filesize($GW_UPLOADPATH . $row['screenshot']) > 0) {
echo '<td><img src="' . $GW_UPLOADPATH . $row['screenshot'] . '" alt="Score image" /></td></tr>';
}
else {
echo '<td><img src="' . @$GW_UPLOADPATH . 'unverified.gif' . '" alt="Unverified score" /></td></tr>';
}
}
echo '</table>';
mysqli_close($dbc);
?>
//addscore.php
<h2>Guitar Wars - Add Your High Score</h2>
<?php
require_once('connectvars.php');
$GW_UPLOADPATH='E:/images/';
if (isset($_POST['submit'])) {
// Grab the score data from the POST
$name = $_POST['name'];
$score = $_POST['score'];
$screenshot= $_FILES['screenshot']['name'];
if (!empty($name) && !empty($score) && !empty($screenshot)) {
// Connect to the database
$target = $GW_UPLOADPATH. $screenshot;
if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) {
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Write the data to the database
$query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$score','$screenshot')";
mysqli_query($dbc, $query);
// Confirm success with the user
echo '<p>Thanks for adding your new high score!</p>';
echo '<p><strong>Name:</strong> ' . $name . '<br />';
echo '<strong>Score:</strong> ' . $score . '</p>';
echo '<img src="' . $GW_UPLOADPATH . $screenshot . '" alt="Score image" /></p>';
echo '<p><a href="index.php"><< Back to high scores</a></p>';
// Clear the score data to clear the form
$name = "";
$score = "";
mysqli_close($dbc);
}
}
else {
echo '<p class="error">Please enter all of the information to add your high score.</p>';
}
}
?>
<hr />
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="MAX_FILE_SIZE" VALUE="32768">
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" />
<br />
<label for="score">Score:</label>
<input type="text" id="score" name="score" value="<?php if (!empty($score)) echo $score; ?>" />
<br/>
<label for="screenshot">screenshot :</label>
<input type="file" id="screenshot" name="screenshot">
<hr />
<input type="submit" value="Add" name="submit" />
</form>
//index.php
<meta />
<title>Guitar Wars - High Scores</title>
<link/>
<h2>Guitar Wars - High Scores</h2>
<p>Welcome, Guitar Warrior, do you have what it takes to crack the high score list? If so, just <a href="addscore.php">add your own score</a>.</p>
<hr />
<?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 guitarwars";
$data = mysqli_query($dbc, $query);
// Loop through the array of score data, formatting it as HTML
echo '<table>';
while ($row = mysqli_fetch_array($data)) {
// Display the score data
echo '<tr><td class="scoreinfo">';
echo '<span class="score">' . $row['score'] . '</span><br />';
echo '<strong>Name:</strong> ' . $row['name'] . '<br />'; //上传的名字
echo '<strong>Date:</strong> ' . $row['data'] . '</td>'; //上传的日期
if (is_file(@$GW_UPLOADPATH . $row['screenshot']) && filesize($GW_UPLOADPATH . $row['screenshot']) > 0) {
echo '<td><img src="' . $GW_UPLOADPATH . $row['screenshot'] . '" alt="Score image" /></td></tr>';
}
else {
echo '<td><img src="' . @$GW_UPLOADPATH . 'unverified.gif' . '" alt="Unverified score" /></td></tr>';
}
}
echo '</table>';
mysqli_close($dbc);
?>
//addscore.php
<h2>Guitar Wars - Add Your High Score</h2>
<?php
require_once('connectvars.php');
$GW_UPLOADPATH='E:/images/';
if (isset($_POST['submit'])) {
// Grab the score data from the POST
$name = $_POST['name'];
$score = $_POST['score'];
$screenshot= $_FILES['screenshot']['name'];
if (!empty($name) && !empty($score) && !empty($screenshot)) {
// Connect to the database
$target = $GW_UPLOADPATH. $screenshot;
if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) {
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Write the data to the database
$query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$score','$screenshot')";
mysqli_query($dbc, $query);
// Confirm success with the user
echo '<p>Thanks for adding your new high score!</p>';
echo '<p><strong>Name:</strong> ' . $name . '<br />';
echo '<strong>Score:</strong> ' . $score . '</p>';
echo '<img src="' . $GW_UPLOADPATH . $screenshot . '" alt="Score image" /></p>';
echo '<p><a href="index.php"><< Back to high scores</a></p>';
// Clear the score data to clear the form
$name = "";
$score = "";
mysqli_close($dbc);
}
}
else {
echo '<p class="error">Please enter all of the information to add your high score.</p>';
}
}
?>
<hr />
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="MAX_FILE_SIZE" VALUE="32768">
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" />
<br />
<label for="score">Score:</label>
<input type="text" id="score" name="score" value="<?php if (!empty($score)) echo $score; ?>" />
<br/>
<label for="screenshot">screenshot :</label>
<input type="file" id="screenshot" name="screenshot">
<hr />
<input type="submit" value="Add" name="submit" />
</form>