看起来像支架错误,但无法弄清楚

时间:2014-04-04 12:18:04

标签: php

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>

<!DOCTYPE = "HTML">
<html>
<head>
<meta charset = "UTF-8">
</head>

<body>
<p1><h1>Guitar Wars - High Scores</h1></p1>
<hr />
<p2> The screenshot must be an image file no greater than 2MB in size.</p2>

<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="MAX_FILE_SIZE" value="2100000" />
<label for="name">Name: </label>
<input type="text" id="name" name="name" /><br />
<label for="score">Score: </label>
<input type="text" id="score" name="score" /><br />
<label for "screenshot">Screen shot: </label>
<input type="file" id="screenshot" name="screenshot" />
<hr />
<input type="submit" name="submit" value="Add" /><br />
</form>

<?php

$name = $_POST['name'];
$score = $_POST['score'];
$screenshot = $_FILES['screenshot']['name'];
$screenshot_type = $_FILES['screenshot']['type'];
$screenshot_size = $_FILES['screenshot']['size'];

require_once('appvars.php');

if (isset($_POST['submit'])){
// Level 1

   if ((!empty($name) && !empty($score)) {
   // Level 2
      $db = mysqli_connect('localhost','****','****','guitarwars') or die('cannot connect to server');
      $query = "INSERT INTO scoreboard (date, name, score, screenshot) VALUES (NOW(),'$name', '$score', '$screenshot')";
      $result = mysqli_query($db,$query) or die (mysqli_error($db));

      echo $name.', your score has been added successfully!<br><br>';


      if (($_FILES['screenshot']['error'] == 0) && ((($screenshot_type == 'image/gif') || ($screenshot_type == 'image/jpeg') || ($screenshot_type == 'image/png')) && (($screenshot_size > 0) && ($screenshot_size <= GW_MAXSIZE)))){
      // Level 3
         echo "File name: ".$screenshot."<br>";
         echo "Type: " . $screenshot_type . "<br>";
         echo "Type: " . $screenshot_size . " bytes<br>";

         $target = GW_UPLOADPATH.$screenshot;
         $move = move_uploaded_file($_FILES['screenshot']['tmp_name'], $target);

         }

       else {
       // Level 3
                echo '<p class = "error">Adding score failed, you can upload only image file under 2MB in size.'.$_FILES['screenshot']['error'].'</p>';
       }
   }
   else {
   // Level 2
        echo '<p class = "error">Adding score failed, you must fill all the fields.</p>';
   }

mysqli_close($db);
}<--- this is the last bracket  
?>

<p><a href ="index.php">Go to the scoreboard!</a></p>
</body>
</html>

当我将光标移到最后一个括号'}'上时,我的文本编辑器(coda)发出哔哔声(警报)。但是我无法弄清楚那个支架有什么问题。

我添加了显示错误的代码,但这些代码都不起作用。

提前谢谢。

2 个答案:

答案 0 :(得分:0)

你的问题在这一行:

if ((!empty($name) && !empty($score)) {

你有(个人。 它应该是:

if (!empty($name) && !empty($score)) {

答案 1 :(得分:0)

if ((!empty($name) && !empty($score)) {

此处)太少,导致{...}周围的()(您的&#34;等级1&#34;大括号)与{{1}}括号重叠。