Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require ('insert.php');
- // If values posted, insert into the database.
- if (isset($_POST['username']) && isset($_POST['password'])){
- $name = $_POST['name'];
- $email = $_POST['email'];
- $username = $_POST['username'];
- $password = $_POST['password'];
- // nimi refers to name, it's correct
- $query = "INSERT INTO `user` (nimi, email, username, password) VALUES('$name', '$email', '$username', '$password')";
- //POST retrieves the data.
- $result = mysqli_query($connection, $query);
- if($result){
- $smsg = "User Created Successfully.";
- }
- else{
- $fmsg = "User Registration Failed";
- }
- }
- mysqli_close($connection);
- ?>
- <html>
- ...
- <body>
- ...
- <div>
- <form method="POST" class="form-horizontal" role="form">
- <!-- Status, how registering went -->
- <?php if(isset($smsg)){ ?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div><?php } ?>
- <?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>
- <!-- Registration form starts -->
- <h2>Form</h2><br>
- <label for="Name"></label>
- <input name="name" type="text" id="name" maxlength="40" placeholder="Ees- ja perenimi" class="form-control" autofocus> <!-- lopp -->
- <label for="email"></label>
- <input name="email" type="email" id="email" maxlength="65" placeholder="Email" class="form-control"> <!-- lopp -->
- <label for="Username"></label>
- <input name="username" type="text" id="userName" maxlength="12" placeholder="Kasutajatunnus/kasutajanimi" class="form-control" required> <!-- lopp -->
- <label for="Password"></label>
- <input name="password" type="password" id="password" maxlength="12" placeholder="Parool" class="form-control" required>
- <button type="submit" class="btn btn-primary btn-block">Join</button>
- </form> <!-- /form -->
- </div> <!-- ./container -->
- ...
- </body>
- </html>
- <?php
- session_start();
- require ('insert.php');
- //Is username and password typed?
- if (isset($_POST['username']) and isset($_POST['password'])){
- //Making vars from inputs
- $username = $_POST['username'];
- $password = $_POST['password'];
- //Checking existent of values.
- $query = "SELECT * FROM `liikmed` WHERE username='$username' and password='$password'";
- $result = mysqli_query($connection, $query) or die(mysqli_error($connection));
- $count = mysqli_num_rows($result);
- //3.1.2 If values equal, create session.
- if ($count == 1){
- $_SESSION['username'] = $username;
- }
- else{
- //If credentials doesn't match.
- $fmsg = "Invalid Login Credentials.";
- }
- }
- //if user logged in, welcome with message
- if (isset($_SESSION['username'])){
- $username = $_SESSION['username'];
- echo "Hai " . $username . "";
- echo "This is the Members Area";
- echo "<a href='logout.php'>Logout</a>";
- }else{}
- ?>
- <html>
- ...
- <body>
- ...
- <div id="bg"></div>
- <form method="POST" class="form-horizontal">
- <h2>Login</h2><br>
- <label for="User"></label>
- <input name="username" type="text" maxlength="15" placeholder="Username" class="form-control" required autofocus>
- <label for="Password"></label>
- <input name="password" type="password" maxlength="50" placeholder="Password" class="form-control" required autofocus>
- <button type="submit" class="btn btn-primary btn-block">Enter</button>
- </form>
- </div>
- ...
- </body>
- </html>
- <?php
- $connection=mysqli_connect("localhost","root","pw");
- if (!$connection){
- die("Database Connection Failed" . mysqli_error($connection));
- }
- $select_db = mysqli_select_db($connection, 'my_database');
- if (!$select_db){
- die("Database Selection Failed" . mysqli_error($connection));
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement