Guest User

Untitled

a guest
Dec 12th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. <?php
  2. $hostname = 'localhost';
  3. $username = 'root';
  4. $password = '';
  5. $databaseName = '508658';
  6. //Open the database connection - exit with error message otherwise
  7. $connection = mysqli_connect($hostname, $username, $password, $databaseName) or exit("Unable to connect to database!");
  8. ?>
  9.  
  10. <?php
  11. session_start();
  12. include ('config.php');
  13. //phpinfo();
  14. ?>
  15. <!DOCTYPE html>
  16. <html>
  17. <head>
  18. <title>Sign Up Page</title>
  19. <link rel="stylesheet" href="css/style.css">
  20. </head>
  21. <body style="background-color:#bdc3c7">
  22. <div id="main-wrapper">
  23. <center><h2>Sign Up Form</h2></center>
  24. <form action="register.php" method="post">
  25. <div class="imgcontainer">
  26. <img src="imgs/avatar.png" alt="Avatar" class="avatar">
  27. </div>
  28. <div class="inner_container">
  29. <label><b>Username</b></label>
  30. <input type="text" placeholder="Enter Username" name="username" required>
  31. <label><b>Password</b></label>
  32. <input type="password" placeholder="Enter Password" name="password" required>
  33. <label><b>Confirm Password</b></label>
  34. <input type="password" placeholder="Enter Password" name="cpassword" required>
  35. <button name="register" class="sign_up_btn" type="submit">Sign Up</button>
  36.  
  37. <a href="index.php"><button type="button" class="back_btn"><< Back to Login</button></a>
  38. </div>
  39. </form>
  40.  
  41. <?php
  42. if(isset($_POST['register']))
  43. {
  44. @$username=$_POST['username'];
  45. @$password=$_POST['password'];
  46. @$cpassword=$_POST['cpassword'];
  47.  
  48. if($password==$cpassword)
  49. {
  50. $query = "select * from user where username='$username'";
  51. //echo $query;
  52. $query_run = mysqli_query($connection,$query);
  53. //echo mysql_num_rows($query_run);
  54. if($query_run)
  55. {
  56. if(mysqli_num_rows($query_run)>0)
  57. {
  58. echo '<script type="text/javascript">alert("This Username Already exists.. Please try another username!")</script>';
  59. }
  60. else
  61. {
  62. $query = "insert into userinfotbl values('$username','$password')";
  63. $query_run = mysqli_query($connection,$query);
  64. if($query_run)
  65. {
  66. echo '<script type="text/javascript">alert("User Registered.. Welcome")</script>';
  67. $_SESSION['username'] = $username;
  68. $_SESSION['password'] = $password;
  69. header( "Location: homepage.php");
  70. }
  71. else
  72. {
  73. echo '<p class="bg-danger msg-block">Registration Unsuccessful due to server error. Please try later</p>';
  74. }
  75. }
  76. }
  77. else
  78. {
  79. echo '<script type="text/javascript">alert("DB error")</script>';
  80. }
  81. }
  82. else
  83. {
  84. echo '<script type="text/javascript">alert("Password and Confirm Password do not match")</script>';
  85. }
  86.  
  87. }
  88. else
  89. {
  90. }
  91. ?>
  92. </div>
  93. </body>
  94. </html>
Add Comment
Please, Sign In to add comment