Guest User

Untitled

a guest
Oct 26th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. <?php
  2. $serverName = "DESKTOP-FDJAOMJ\sqlexpress"; //serverNameinstanceName
  3. $connectionInfo = array( "Database"=>"sgo", "UID"=>"arm", "PWD"=>"arm123");
  4. $con = sqlsrv_connect( $serverName, $connectionInfo);
  5.  
  6. if( $con ) {
  7. echo "Connection established.<br />";
  8. }else{
  9. echo "Connection could not be established.<br />";
  10. die( print_r( sqlsrv_errors(), true));
  11. }
  12. ?>
  13.  
  14. <!DOCTYPE html>
  15. <html>
  16. <body>
  17. <?php
  18. require('db.php');
  19. session_start();
  20. // If form submitted, insert values into the database.
  21. if (isset($_POST['username'])){
  22. // removes backslashes
  23. $username = stripslashes($_REQUEST['username']);
  24. //escapes special characters in a string
  25. //$username = unpack($con,$username);
  26. $password = stripslashes($_REQUEST['password']);
  27. //$password = addslashes($con,$password);
  28. //Checking is user existing in the database or not
  29. $query = "SELECT * FROM `users` WHERE username='$username' and password='$password'";
  30. $params = array();
  31. $result = sqlsrv_query($con,$query,$params) or die(sqlsrv_errors());
  32. $rows = sqlsrv_num_rows($result);
  33. if($rows==1){
  34. $_SESSION['username'] = $username;
  35. // Redirect user to index.php
  36. header("Location: index.php");
  37. }else{
  38. echo "<div class='form'>
  39. <h3>Username/password is incorrect.</h3>
  40. <br/>Click here to <a href='login.php'>Login</a></div>";
  41. }
  42. }else{
  43. ?>
  44. <div class="form">
  45. <h1>Log In</h1>
  46. <form action="" method="post" name="login">
  47. <input type="text" name="username" placeholder="Username" required />
  48. <input type="password" name="password" placeholder="Password" required />
  49. <input name="submit" type="submit" value="Login" />
  50. </form>
  51. <p>Not registered yet? <a href='registration.php'>Register Here</a></p>
  52. </div>
  53. <?php } ?>
  54. </body>
  55. </html>
Add Comment
Please, Sign In to add comment