I hope someone can help
I'm sure this is easy. My program works fine if I have only some else comments but when I ass another one, the program crashes. Is the answer to use switch? Even though the new comment is the only extra one I need? How do I add the extra condition? In this case it is the "Please enter the verification pass phrase exactly as shown".
I don't think there is anything inherently wrong with the code. I may well be wrong!
Any help much appreciated
code below
Code: Select all
<?php
session_start();
//Define the uplaod path and maximum file size constants
require_once('appvars.php');
require_once('connectvars.php');
if (isset($_POST['submit'])) {
// Grab the score data from the POST
$first_name = trim($_POST['first_name']);
$last_name = trim($_POST['last_name']);
$score = trim($_POST['score']);
$screenshot = trim($_FILES['screenshot']['name']);
$user_pass_phrase = sha1($_POST['verify']);
if ($_SESSION['pass_phrase'] == $user_pass_phrase) {
if (!empty($first_name) && !empty($score) && !empty($screenshot)) {
if ($_FILES['screenshot']['error'] == 0) {
//Move the file to the target upload folder
$target = GW_UPLOADPATH . $screenshot;
if(move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) {
//Connect to the database
$dbc = mysqli_connect('localhost', 'root', 'skipper', 'elvis_store');
//Write the data to the database
$query = "INSERT into gwdb values (0, '$first_name', '$last_name', '$score', '$screenshot', 0)";
mysqli_query($dbc, $query);
//Confirm success with the user
echo '<p>Thanks for submitting your new high score!</p>';
echo '<p><strong>First_Name:</strong> ' . $first_name . '<br />';
echo '<strong>Last_Name:</strong> ' . $last_name . ' <br />';
echo '<strong>Score:</strong> ' . $score . '</p>';
echo '<img src="' . GW_UPLOADPATH . $screenshot . '" alt="Score image" /></p>';
echo '<p><a href="index1.php"><<Back to high scores</a></p>';
//Clear the score data to clear form
$first_name = "";
$last_name = "";
$score = "";
$screenshot ="";
mysqli_close($dbc);
}
else {
echo '<p class="error">Sorry there was a problem uploading your screen shot image.</p>';
}
}
}
else {
echo '<p class="error">The screen shot must be a GIF,JPEG or PNG image file no greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size.</p>';
}
//Try to delete the temporary screen shot image file
@unlink($_FILES['screenshot']['tmp_name']);
}
else
{
echo '<p class="error">Please enter all of the information to add your high score.</p>';
}
else {
echo '<p class="error">Please enter the verifaction pass phrase exactly as shown.</p>';
}}
?>