Guest User

Untitled

a guest
Apr 20th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <?php
  2. ob_start();
  3. $host="127.0.0.1"; // Host name
  4. $username="root"; // Mysql username
  5. $password=""; // Mysql password
  6. $db_name="student"; // Database name
  7. $tbl_name="student_login"; // Table name
  8.  
  9. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  10. mysql_select_db("$db_name")or die("cannot select DB");
  11.  
  12. // Define $myusername and $mypassword
  13. $myusername=$_POST['Username'];
  14. $mypassword=$_POST['Password'];
  15.  
  16. if (isset($_POST['submit'])) {
  17.  
  18.  
  19. if (!$_POST['username'] | !$_POST['password'] ) {
  20. die('You did not complete all of the required fields');
  21. }
  22.  
  23. if (!get_magic_quotes_gpc()) {
  24. $_POST['username'] = addslashes($_POST['username']);
  25. }
  26. $usercheck = $_POST['username'];
  27. $check = mysql_query("SELECT username FROM $tbl_name WHERE username = '$usercheck'")
  28. or die(mysql_error());
  29. $check2 = mysql_num_rows($check);
  30.  
  31. if ($check2 != 0) {
  32. die('Sorry, the username '.$_POST['username'].' is already in use.');
  33. }
  34.  
  35. $_POST['password'] = md5($_POST['password']);
  36. if (!get_magic_quotes_gpc()) {
  37. $_POST['password'] = addslashes($_POST['password']);
  38. $_POST['username'] = addslashes($_POST['username']);
  39. }
  40.  
  41. $insert = "INSERT INTO 'student_login' (username, password)
  42. VALUES ('".$_POST['username']."', '".$_POST['password']."')";
  43. $add_member = mysql_query($insert);
  44.  
  45. ?>
  46.  
  47. <h1>Registered</h1>
  48. <p>Thank you, you have registered - you may now login<a href ="checklogin2.php"</a></p>
  49.  
  50. <?php
  51. }
  52. else
  53. {
  54. ?>
  55.  
  56.  
  57. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  58. <table border="0">
  59. <tr><td>Username:</td><td>
  60. <input type="text" name="username" maxlength="60">
  61. </td></tr>
  62. <tr><td>Password:</td><td>
  63. <input type="password" name="password" maxlength="10">
  64. </td></tr>
  65. <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table>
  66. </form>
  67.  
  68. <?php
  69. }
  70. ?>
Add Comment
Please, Sign In to add comment