Chưa từng có ‘}’ trong C:\xampp\htdocs\new folder\registration.php trên dòng 88

lập trình


  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  }

Những gì tôi đã thử:

Tôi đã thử mọi cách nhưng không thiếu dấu ngoặc nào

Giải pháp 1

Và bạn đã xem qua Dòng 88?

Đây là:

<?php } ?>

Giải pháp 2

Nhìn vào thông báo lỗi và mã của bạn:

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{
?>

Điều đó không có nghĩa là nó phải thiếu “}”, mà có thể là nó có thêm “}”.
Vậy tại sao lại có hai “}” ngay trước else?

Bạn có thể gặp phải lỗi cú pháp hàng ngày, có thể nhiều lần trong ngày khi bạn đang viết mã – tất cả chúng ta đều mắc phải bất kể chúng ta có bao nhiêu kinh nghiệm! Đôi khi, chúng ta viết sai chính tả một biến hoặc một từ khóa; đôi khi chúng ta quên đóng một chuỗi hoặc một khối mã. Đôi khi con mèo đi qua bàn phím của bạn và gõ thứ gì đó thực sự kỳ lạ. Đôi khi chúng ta quên mất một cuộc gọi phương thức cần bao nhiêu tham số.

Tất cả chúng ta đều phạm sai lầm.

Và bởi vì tất cả chúng ta đều làm điều đó nên tất cả chúng ta đều phải sửa lỗi cú pháp – và việc tự học cách tự tìm hiểu và sửa chúng sẽ nhanh hơn rất nhiều so với việc đợi người khác sửa chúng cho bạn! Vì vậy, hãy đầu tư một chút thời gian vào việc học cách đọc thông báo lỗi và cách diễn giải mã của bạn như được viết dựa trên những gì trình biên dịch thông báo cho bạn là sai – nó thực sự đang cố gắng hữu ích!

Vì vậy hãy đọc cái này: Cách viết mã để giải quyết vấn đề, Hướng dẫn cho người mới bắt đầu Phần 2: Lỗi cú pháp[^] – nó sẽ giúp ích cho bạn vào lần tới khi bạn gặp lỗi biên dịch!

コメント

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