第 88 行 C:\xampp\htdocs\newfolder\registration.php 中不匹配的“}”

编程

[ad_1]

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

这并不意味着它必须缺少“}”,它可能意味着它是一个额外的“}”。
那么为什么前面有两个“}” else

您应该预料到每天都会遇到语法错误,在编码时可能一天会出现很多次 – 无论我们有多少经验,我们都会遇到这种情况! 有时,我们会拼错变量或关键字; 有时我们忘记关闭字符串或代码块。 有时,猫会走过你的键盘并输入一些非常奇怪的东西。 有时我们只是忘记了方法调用需要多少个参数。

我们都会犯错。

因为我们都这样做,所以我们都必须修复语法错误 – 自己学习如何修复它们比等待别人为您修复它们要快得多! 因此,花一点时间学习如何阅读错误消息,以及如何根据编译器告诉您的错误内容来解释您的代码 – 这确实是有帮助的!

所以请阅读以下内容: 如何编写代码来解决问题,初学者指南第 2 部分:语法错误[^] – 下次遇到编译错误时它应该会对您有所帮助!

[ad_2]

コメント

标题和URL已复制