Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 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 and 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 to 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.   // Make 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 to thank you page.
  49.         Header("Location: register.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