【解決方法】C:\xampp\htdocs\newfolder\registration.php の 88 行目に一致しない ‘}’

プログラミングQA


  1  <html>
  2  <head>
  3  <meta charset="utf-8">
  4  <title>Registration</title>
  5  <link rel="stylesheet" href="css/style.css" />
  6  </head>
  7  <body>
  8  <?php
  9  require('db.php');
 10  // If form submitted, insert values into the database.
 11  if (isset($_REQUEST['username'])){
 12          // removes backslashes
 13  	$username = stripslashes($_REQUEST['username']);
 14          //escapes special characters in a string
 15  	$username = mysqli_real_escape_string($con,$username); 
 16  	$email = stripslashes($_REQUEST['email']);
 17  	$email = mysqli_real_escape_string($con,$email);
 18  	$password = stripslashes($_REQUEST['password']);
 19  	$password = mysqli_real_escape_string($con,$password);
 20  	$trn_date = date("Y-m-d H:i:s");
 21          $query = "INSERT into `users` (username, password, email, trn_date)
 22  VALUES ('$username', '".md5($password)."', '$email', '$trn_date')";
 23          $result = mysqli_query($con,$query);
 24          if($result){
 25              echo "<div class='form'>
 26  <h3>You are registered successfully.</h3>
 27  <br/>Click here to <a href='login.php'>Login</a></div>";
 28          }
 29      }else{
 30  ?>
 31  <div class="form">
 32  <h1>Registration</h1>
 33  <form name="registration" action="" method="post">
 34  <input type="text" name="username" placeholder="Username" required />
 35  <input type="email" name="email" placeholder="Email" required />
 36  <input type="password" name="password" placeholder="Password" required />
 37  <input type="submit" name="submit" value="Register" />
 38  </form>
 39  </div>
 40  <?php } ?>
 41  </body>
 42  </html>
 43  <!DOCTYPE html>
 44  <html>
 45  <head>
 46  <meta charset="utf-8">
 47  <title>Login</title>
 48  <link rel="stylesheet" href="css/style.css" />
 49  </head>
 50  <body>
 51  <?php<!DOCTYPE html>
 52  
 53  require('db.php');
 54  session_start();
 55  // If form submitted, insert values into the database.
 56  if (isset($_POST['username'])){
 57          // removes backslashes
 58  	$username = stripslashes($_REQUEST['username']);
 59          //escapes special characters in a string
 60  	$username = mysqli_real_escape_string($con,$username);
 61  	$password = stripslashes($_REQUEST['password']);
 62  	$password = mysqli_real_escape_string($con,$password);
 63  	//Checking is user existing in the database or not
 64          $query = "SELECT * FROM `users` WHERE username='$username'
 65  and password='".md5($password)."'";
 66  	$result = mysqli_query($con,$query) or die(mysql_error());
 67  	$rows = mysqli_num_rows($result);
 68          if($rows==1){
 69  	    $_SESSION['username'] = $username;
 70              // Redirect user to index.php
 71  	    header("Location: index.php");
 72           }else{
 73  	echo "<div class='form'>
 74  <h3>Username/password is incorrect.</h3>
 75  <br/>Click here to <a href='login.php'>Login</a></div>";
 76  	}
 77      }else{
 78  ?>
 79  <div class="form">
 80  <h1>Log In</h1>
 81  <form action="" method="post" name="login">
 82  <input type="text" name="username" placeholder="Username" required />
 83  <input type="password" name="password" placeholder="Password" required />
 84  <input name="submit" type="submit" value="Login" />
 85  </form>
 86  <p>Not registered yet? <a href='registration.php'>Register Here</a></p>
 87  </div>
 88  <?php } ?>
 89  </body>
 90  </html>
 91  <?php
 92  // Enter your Host, username, password, database below.
 93  // I left password empty because i do not set password on localhost.
 94  $con = mysqli_connect("localhost","root","","registration");
 95  // Check connection
 96  if (mysqli_connect_errno())
 97    {
 98    echo "Failed to connect to MySQL: " . mysqli_connect_error();
 99    }
100  ?>
101  <?php
102  session_start();
103  if(!isset($_SESSION["username"])){
104  header("Location: login.php");
105  exit(); }
106  ?>
107  <?php
108  //include auth.php file on all secure pages
109  include("auth.php");
110  ?>
111  <!DOCTYPE html>
112  <html>
113  <head>
114  <meta charset="utf-8">
115  <title>Welcome Home</title>
116  <link rel="stylesheet" href="css/style.css" />
117  </head>
118  <body>
119  <div class="form">
120  <p>Welcome <?php echo $_SESSION['username']; ?>!</p>
121  <p>This is secure area.</p>
122  <p><a href="dashboard.php">Dashboard</a></p>
123  <a href="logout.php">Logout</a>
124  </div>
125  </body>
126  <?php
127  require('db.php');
128  include("auth.php");
129  ?>
130  <!DOCTYPE html>
131  <html>
132  <head>
133  <meta charset="utf-8">
134  <title>Dashboard - Secured Page</title>
135  <link rel="stylesheet" href="css/style.css" />
136  </head>
137  <body>
138  <div class="form">
139  <p>Dashboard</p>
140  <p>This is another secured page.</p>
141  <p><a href="index.php">Home</a></p>
142  <a href="logout.php">Logout</a>
143  </div>
144  </body>
145  </html>
146  <?php
147  session_start();
148  // Destroying All Sessions
149  if(session_destroy())
150  {
151  // Redirecting To Home Page
152  header("Location: login.php");
153  }
154  ?>
155  body {
156       font-family:Arial, Sans-Serif;
157  }
158  .clearfix:before, .clearfix:after{
159       content: "";
160       display: table;
161  }
162  .clearfix:after{
163       clear: both;
164  }
165  a{
166       color:#0067ab;
167       text-decoration:none;
168  }
169  a:hover{
170       text-decoration:underline;
171  }
172  .form{
173       width: 300px;
174       margin: 0 auto;
175  }
176  input[type='text'], input[type='email'],
177  input[type='password'] {
178       width: 200px;
179       border-radius: 2px;
180       border: 1px solid #CCC;
181       padding: 10px;
182       color: #333;
183       font-size: 14px;
184       margin-top: 10px;
185  }
186  input[type='submit']{
187       padding: 10px 25px 8px;
188       color: #fff;
189       background-color: #0067ab;
190       text-shadow: rgba(0,0,0,0.24) 0 1px 0;
191       font-size: 16px;
192       box-shadow: rgba(255,255,255,0.24) 0 2px 0 0 inset,#fff 0 1px 0 0;
193       border: 1px solid #0164a5;
194       border-radius: 2px;
195       margin-top: 10px;
196       cursor:pointer;
197  }
198  input[type='submit']:hover {
199       background-color: #024978;
200  }

私が試したこと:

すべて試しましたが、括弧がありませんでした

解決策 1

88行目はご覧になりましたか?

これは次のとおりです。

<?php } ?>

解決策 2

エラー メッセージとコードを確認してください。

Unmatched '}' in C:\xampp\htdocs\new folder\registration.php on line 88

         }else{
	echo "<div class='form'>
<h3>Username/password is incorrect.</h3>
<br/>Click here to <a href='login.php'>Login</a></div>";
	}
    }else{
?>

これは、「}」が欠落している必要があるという意味ではなく、余分な「}」である可能性があります。
では、なぜ直前に「}」が 2 つあるのでしょうか。 else?

コーディング中には、おそらく 1 日に何度も構文エラーが発生することを覚悟しておく必要があります。どれだけ経験があるかに関係なく、誰もが経験します。 場合によっては、変数やキーワードのスペルを間違えることがあります。 文字列やコード ブロックを閉じるのを忘れることがあります。 猫がキーボードの上を歩いて、非常に奇妙な文字を入力することがあります。 メソッド呼び出しに必要なパラメーターの数を忘れてしまうことがあります。

我々はすべての間違いを犯します。

そして、私たち全員が構文エラーを修正する必要があるため、構文エラーを修正する必要があります。そして、他の人が修正してくれるのを待つよりも、自分で修正する方法を学んで修正する方がずっと早いのです。 したがって、エラー メッセージの読み方と、コンパイラーが間違っていると伝えている内容に照らして書かれたコードを解釈する方法を学ぶのに少し時間を投資してください。それは本当に役に立ちます。

それで、これを読んでください: 問題を解決するコードの書き方、初心者ガイド パート 2: 構文エラー[^] – 次回コンパイル エラーが発生したときに役立つはずです。

コメント

タイトルとURLをコピーしました