Advertisement
Guest User

MCadue - Project 1

a guest
Apr 6th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. //Registration Page
  2.  
  3. <html>
  4.  
  5. <body>
  6.  
  7. <h3>Registration Form</h3><br>
  8. <form action="thankyou.php" method="post">
  9. First name: <input type="text" name="fname"><br>
  10. Last name: <input type="text" name="lname"><br>
  11. Age: <input type="number" name="age"><br>
  12. Address: <input type="text" name="address"><br>
  13. E-Mail Address: <input type="text" name="email"><br>
  14. Would you like to receive e-mails with discounts and special offers?:
  15. <input type="checkbox" name="optin"><br>
  16. Enter Image Text
  17. <input name="captcha" type="text">
  18. <img src="captcha.php" /><br>
  19. <input type="submit" value="Submit">
  20. </form>
  21.  
  22. </body>
  23.  
  24. </html>
  25.  
  26. //ThankYou Page
  27.  
  28.  
  29.     $servername = "localhost";
  30.     $username = "";
  31.     $password = "";
  32.     $dbname = "";
  33.  
  34.     // Create connection
  35.     $conn = new mysqli($servername, $username, $password, $dbname);
  36.  
  37.     // Check connection
  38.     if ($conn->connect_error) {
  39.             die("Connection failed: " . $conn->connect_error);
  40.     }
  41.     else {
  42.    
  43.         $newaddress = $_POST["address"];   
  44.         $newage = $_POST["age"];
  45.         $newemail = $_POST["email"];
  46.         $newfname = $_POST["fname"];
  47.         $newlname = $_POST["lname"];
  48.         $newoptin = $_POST["optin"];
  49.  
  50.         if ($newoptin == "on")
  51.         {
  52.             $newoptin = 1;
  53.         }
  54.         else {
  55.             $newoptin = 0;
  56.         }
  57.        
  58.  
  59.  
  60.  
  61.         $sql = "INSERT INTO UserInfo (Address, Age, Email, FirstName, LastName, Offers)
  62.         VALUES ('$newaddress', '$newage', '$newemail', '$newfname', '$newlname', $newoptin)";
  63.  
  64.         if ($conn->query($sql) === TRUE) {
  65.             echo "New record created successfully";
  66.    
  67.         }
  68.         else {
  69.             echo "Error: " . $sql . "<br>" . $conn->error;
  70.         }
  71.  
  72.         $conn->close();
  73.  
  74.         echo '<h4>Thank you!</h4>';
  75.         echo '<h2>A representative will contact you within 5 business days if</h2>';
  76.         echo '<h2>you meet the requirements to begin the free trial.</h2>';
  77.     }
  78.  
  79. }
  80. else
  81. {
  82.     die("Wrong Code Entered - Please go back using browser back button and try again.");
  83. }
  84.  
  85. ?>
  86.  
  87. </body>
  88. </html>
  89.  
  90. //CAPTCHA
  91.  
  92. <?php
  93.  
  94. session_start();
  95. $code=rand(1000,9999);
  96. $_SESSION["code"]=$code;
  97. $im = imagecreatetruecolor(50, 24);
  98. $bg = imagecolorallocate($im, 22, 86, 165); //background color blue
  99. $fg = imagecolorallocate($im, 255, 255, 255);//text color white
  100. imagefill($im, 0, 0, $bg);
  101. imagestring($im, 5, 5, 5,  $code, $fg);
  102. header("Cache-Control: no-cache, must-revalidate");
  103. header('Content-type: image/png');
  104. imagepng($im);
  105. imagedestroy($im);
  106.  
  107. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement