Advertisement
Guest User

Untitled

a guest
Feb 13th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. <?php
  2. require ('insert.php');
  3. // If values posted, insert into the database.
  4. if (isset($_POST['username']) && isset($_POST['password'])){
  5. $name = $_POST['name'];
  6. $email = $_POST['email'];
  7. $username = $_POST['username'];
  8. $password = $_POST['password'];
  9.  
  10. // nimi refers to name, it's correct
  11. $query = "INSERT INTO `user` (nimi, email, username, password) VALUES('$name', '$email', '$username', '$password')";
  12.  
  13. //POST retrieves the data.
  14. $result = mysqli_query($connection, $query);
  15.  
  16. if($result){
  17. $smsg = "User Created Successfully.";
  18. }
  19. else{
  20. $fmsg = "User Registration Failed";
  21. }
  22. }
  23.  
  24. mysqli_close($connection);
  25. ?>
  26. <html>
  27. ...
  28. <body>
  29. ...
  30. <div>
  31.  
  32. <form method="POST" class="form-horizontal" role="form">
  33.  
  34. <!-- Status, how registering went -->
  35. <?php if(isset($smsg)){ ?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div><?php } ?>
  36. <?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>
  37.  
  38.  
  39. <!-- Registration form starts -->
  40. <h2>Form</h2><br>
  41.  
  42.  
  43. <label for="Name"></label>
  44. <input name="name" type="text" id="name" maxlength="40" placeholder="Ees- ja perenimi" class="form-control" autofocus> <!-- lopp -->
  45.  
  46. <label for="email"></label>
  47. <input name="email" type="email" id="email" maxlength="65" placeholder="Email" class="form-control"> <!-- lopp -->
  48.  
  49.  
  50. <label for="Username"></label>
  51. <input name="username" type="text" id="userName" maxlength="12" placeholder="Kasutajatunnus/kasutajanimi" class="form-control" required> <!-- lopp -->
  52.  
  53. <label for="Password"></label>
  54. <input name="password" type="password" id="password" maxlength="12" placeholder="Parool" class="form-control" required>
  55.  
  56. <button type="submit" class="btn btn-primary btn-block">Join</button>
  57. </form> <!-- /form -->
  58.  
  59. </div> <!-- ./container -->
  60. ...
  61. </body>
  62. </html>
  63.  
  64. <?php
  65. session_start();
  66. require ('insert.php');
  67.  
  68. //Is username and password typed?
  69. if (isset($_POST['username']) and isset($_POST['password'])){
  70. //Making vars from inputs
  71. $username = $_POST['username'];
  72. $password = $_POST['password'];
  73. //Checking existent of values.
  74. $query = "SELECT * FROM `liikmed` WHERE username='$username' and password='$password'";
  75.  
  76. $result = mysqli_query($connection, $query) or die(mysqli_error($connection));
  77. $count = mysqli_num_rows($result);
  78. //3.1.2 If values equal, create session.
  79. if ($count == 1){
  80. $_SESSION['username'] = $username;
  81. }
  82. else{
  83. //If credentials doesn't match.
  84. $fmsg = "Invalid Login Credentials.";
  85. }
  86. }
  87. //if user logged in, welcome with message
  88. if (isset($_SESSION['username'])){
  89. $username = $_SESSION['username'];
  90. echo "Hai " . $username . "";
  91. echo "This is the Members Area";
  92. echo "<a href='logout.php'>Logout</a>";
  93.  
  94. }else{}
  95. ?>
  96.  
  97. <html>
  98. ...
  99. <body>
  100. ...
  101. <div id="bg"></div>
  102.  
  103.  
  104. <form method="POST" class="form-horizontal">
  105. <h2>Login</h2><br>
  106.  
  107. <label for="User"></label>
  108. <input name="username" type="text" maxlength="15" placeholder="Username" class="form-control" required autofocus>
  109.  
  110. <label for="Password"></label>
  111. <input name="password" type="password" maxlength="50" placeholder="Password" class="form-control" required autofocus>
  112.  
  113. <button type="submit" class="btn btn-primary btn-block">Enter</button>
  114.  
  115. </form>
  116. </div>
  117. ...
  118. </body>
  119. </html>
  120.  
  121. <?php
  122. $connection=mysqli_connect("localhost","root","pw");
  123. if (!$connection){
  124. die("Database Connection Failed" . mysqli_error($connection));
  125. }
  126. $select_db = mysqli_select_db($connection, 'my_database');
  127. if (!$select_db){
  128. die("Database Selection Failed" . mysqli_error($connection));
  129. }
  130. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement