Click here to Skip to main content
16,015,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
  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  }


What I have tried:

I tried everything but no brackets were missing
Posted
Updated 10-Nov-22 9:59am
v2

And you had a look to Line 88?

This it is:
<?php } ?>
 
Share this answer
 
v2
Look at the error message and your code:
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{
?>
That doesn't mean it has to be a missing "}", it can means it's an extra "}".
So why are there two "}" immediately before the else?

You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!
 
Share this answer
 
Comments
0x01AA 10-Nov-22 15:12pm    
Out of scope: I tried to add line numbers to the original question. But if I try to edit the code I see only strange things, Bugs and Suggestions[^]. Any idea on that?
OriginalGriff 10-Nov-22 15:24pm    
HTML encoding: the ampersand introduces a symbol that browsers render to the character:
&lt; renders to a "less than", and so on. Without that, the code fragment gets interpreted as HTML for the page and nobody can read it!
0x01AA 10-Nov-22 15:51pm    
That was not same in the past ;) In the past. editing a question even it was html no ampersand appeared.
OriginalGriff 10-Nov-22 16:29pm    
I'm pretty sure it was - it depends on how the OP posted it. One of the paste options is "Encode HTML" which converts all such characters for you. If you use that and then add your pre tags, you'll get what you saw.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900