Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.94 KB | None | 0 0
  1. <?php session_start();
  2.  
  3. $_SESSION['username'] = $_POST["user_name"];
  4.  
  5. ?>
  6.  
  7. <html>
  8. <head>
  9. <title>Test Registration</title>
  10. </head>
  11. <body>
  12.        
  13.    
  14.     <form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
  15.  
  16.  
  17.  
  18. <?php
  19.  
  20. $name_good = false;
  21. $email_good = false;
  22. $pass_good = false;
  23.  
  24.  
  25. // Check if $username is set if so check $username against conditions if false echo error if true echo $username.
  26. if (isset($_POST["user_name"])) {
  27.     if (strlen($_POST["user_name"]) < 3 || strlen($_POST["user_name"]) > 20 ) {
  28.    
  29.         echo "<p><font color=\"red\">*</font> Student's Name: <input type=\"text\" name=\"user_name\" value=\"".$_POST["user_name"]."\" /> <font color='red'>Your username must be more than 3 characters and less than 20.</font>"."</p>";
  30.        
  31. } else {       
  32.  
  33.         $name_good = $_POST["user_name"];
  34.     }
  35.    
  36. } else {
  37.  
  38. echo "<p><font color=\"red\">*</font> Student's Name: <input type=\"text\" name=\"user_name\" /></p>";
  39.  
  40. }
  41.  
  42. // Check if $useremail is set if so check if userconemail matches if not show error then check if useremail contains @ if not show an error.      
  43. if (isset($_POST["user_email"])) {
  44.     if (strcmp($_POST["user_email"], $_POST["user_con_email"])) {
  45.    
  46.        echo "<p><font color=\"red\">*</font> Parent's Email: <input type=\"text\" name=\"user_email\" size=\"40\" value=\"".$_POST["user_email"]."\" /> <font color='red'>Your Emails do not match, silly goose.</font>"."<br>";
  47.  
  48. } elseif (stristr($_POST["user_email"], '@')) {    
  49.    
  50.        $email_good = $_POST["user_email"];
  51.  
  52.     }
  53.        
  54. } else {
  55.        
  56.        echo "<p><font color=\"red\">*</font> Parent's Email: <input type=\"text\" name=\"user_email\" size=\"40\" /></p>"."<p><font color=\"red\">*</font> Confirm Email: <input type=\"text\" name=\"user_con_email\" size=\"40\" /></p>";
  57.        
  58. }  
  59.  
  60. // Check $userpass is set as well as more than 8 characters and if $userpass and $userconpass match if not shows errors.       
  61. if (isset($_POST["user_pass"])) {
  62.     if (strcmp($_POST["user_pass"], $_POST["user_con_pass"])) {
  63.    
  64.         echo "<font color=\"red\">*</font> Password: <input type=\"text\" name=\"user_pass\" value=\"".$_POST["user_pass"]."\" /> <font color='red'>Your Passwords do not match silly goose.</font>"."</br>";
  65.  
  66. } elseif (strlen($_POST["user_pass"]) < 8 ) {
  67.  
  68.         echo "<font color=\"red\">*</font> Password: <input type=\"text\" name=\"user_pass\" value=\"".$_POST["user_pass"]."\" /> <font color='red'>Your Password must be at least 8 characters.</font>"."<br>";
  69.        
  70. } else {
  71.        
  72.         $pass_good = $_POST["user_pass"];
  73.    
  74.     }
  75.    
  76. }   else {
  77.  
  78.         echo "<p><font color=\"red\">*</font> Student Password: <input type=\"password\" name=\"user_pass\" /></p>"."<p><font color=\"red\">*</font> Confirm Password: <input type=\"password\" name=\"user_con_pass\" /></p>"."<br>";
  79.        
  80. }  
  81.  
  82.    
  83.  if ($name_good && $email_good && $pass_good) {
  84.    
  85.    
  86. // Creat a variable to hold the query to issue, which will insert data into the database.
  87. $do_sql = "INSERT INTO `user_db`.`user_info` ( `user_name`, `user_email`, `user_pass` ) VALUES ('$name_good', '$email_good', '$pass_good')";
  88.  
  89. // Add the connection information, add the die() function to end the script and display the mysql_error() function if the connection can not be made.
  90. $connection = @mysql_connect("localhost", "chacho", "mysqltraining")
  91. or die(mysql_error());
  92.  
  93. // Issue a query using the mysql_query() function. include the @ to supress warnings, as well as the die() function to cause the script to end and a message to display if the query fails.
  94. $created = @mysql_query($do_sql, $connection) or die(mysql_error());
  95.  
  96. }
  97.  
  98. // Test the value of $created. If it's true, the query was successful, and a variable is created to hold the message, "Database has been created".
  99. if (isset($created)) {
  100. header("location: test_profile.php");
  101.        
  102. }
  103.    
  104. ?>
  105.  
  106.  
  107. <a href=/new_test.php>Resubmit Form</a> <input type="submit" name="submit" value="Submit">
  108. </form>
  109.  
  110. </body>
  111. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement