Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <?php
  2.  
  3. // dbConfig.php is a file that contains your
  4. // database connection information. This
  5. // tutorial assumes a connection is made from
  6. // this existing file.
  7. include ("dbConfig.php");
  8.  
  9.  
  10. //Input vaildation <strong class="highlight">and</strong> the dbase code
  11. if ( $_GET["op"] == "reg" )
  12. {
  13. $bInputFlag = false;
  14. foreach ( $_POST as $field )
  15. {
  16. if ($field == "")
  17. {
  18. $bInputFlag = false;
  19. }
  20. else
  21. {
  22. $bInputFlag = true;
  23. }
  24. }
  25. // If we had problems with the input, exit with error
  26. if ($bInputFlag == false)
  27. {
  28. die( "Problem with your registration info. "
  29. ."Please go back and try again.");
  30. }
  31.  
  32. // Fields are clear, add user <strong class="highlight">to</strong> database
  33. // Setup query
  34. $q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) "
  35. ."VALUES ('".$_POST["username"]."', "
  36. ."PASSWORD('".$_POST["password"]."'), "
  37. ."'".$_POST["email"]."')";
  38. // Run query
  39. $r = mysql_query($q);
  40.  
  41. // <strong class="highlight">Make</strong> sure query inserted user successfully
  42. if ( !mysql_insert_id() )
  43. {
  44. die("Error: User not added to database.");
  45. }
  46. else
  47. {
  48. // Redirect <strong class="highlight">to</strong> thank you <strong class="highlight">page</strong>.
  49. Header("Location: <strong class="highlight">register</strong>.php?op=thanks");
  50. }
  51. } // end if
  52.  
  53.  
  54. //The thank you page
  55. elseif ( $_GET["op"] == "thanks" )
  56. {
  57. echo "<h2>Thanks for registering!</h2>";
  58. }
  59.  
  60. //The web form for input ability
  61. else
  62. {
  63. echo "<form action=\"?op=reg\" method=\"POST\">\n";
  64. echo "Username: <input name=\"username\" MAXLENGTH=\"16\"><br />\n";
  65. echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"><br />\n";
  66. echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"><br />\n";
  67. echo "<input type=\"submit\">\n";
  68. echo "</form>\n";
  69. }
  70. // EOF
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement