Advertisement
wilmers16

New Code

Aug 10th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.51 KB | None | 0 0
  1. <?php require_once('Connections/sql_connection.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($database_sql_connection,$theValue) : mysqli_escape_string($database_sql_connection,$theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. // *** Redirect if username exists
  35. $MM_flag="MM_insert";
  36. if (isset($_POST[$MM_flag])) {
  37.   $MM_dupKeyRedirect="Register.php";
  38.   $loginUsername = $_POST['email_address'];
  39.   $LoginRS__query = sprintf("SELECT email_address FROM employee WHERE email_address=%s", GetSQLValueString($loginUsername, "text"));
  40.   mysqli_select_db($sql_connection,$database_sql_connection);
  41.   $LoginRS=mysqli_query($LoginRS__query, $sql_connection) or die(mysql_error());
  42.   $loginFoundUser = mysqli_num_rows($LoginRS);
  43.  
  44.   //if there is a row in the database, the username was found - can not add the requested username
  45.   if($loginFoundUser){
  46.     $MM_qsChar = "?";
  47.     //append the username to the redirect page
  48.     if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
  49.     $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
  50.     header ("Location: $MM_dupKeyRedirect");
  51.     exit;
  52.   }
  53. }
  54.  
  55. $editFormAction = $_SERVER['PHP_SELF'];
  56. if (isset($_SERVER['QUERY_STRING'])) {
  57.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  58. }
  59.  
  60. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "RegisterForm")) {
  61.   $insertSQL = sprintf("INSERT INTO employee (first_name, last_name, email_address, password) VALUES (%s, %s, %s, %s)",
  62.                        GetSQLValueString($_POST['first_name'], "text"),
  63.                        GetSQLValueString($_POST['last_name'], "text"),
  64.                        GetSQLValueString($_POST['email_address'], "text"),
  65.                        GetSQLValueString($_POST['password'], "text"));
  66.  
  67.   mysqli_select_db($database_sql_connection, $sql_connection);
  68.   $Result1 = mysqli_query($insertSQL, $sql_connection) or die(mysql_error());
  69.  
  70.   $insertGoTo = "Login.php";
  71.   if (isset($_SERVER['QUERY_STRING'])) {
  72.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  73.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  74.   }
  75.   header(sprintf("Location: %s", $insertGoTo));
  76. }
  77.  
  78. mysqli_select_db($sql_connection,$database_sql_connection);
  79. $query_Register = "SELECT employee.first_name, employee.last_name, employee.email_address, employee.password FROM employee";
  80. $Register = mysqli_query($sql_connection,$query_Register) or die(mysqli_error());
  81. $row_Register = mysqli_fetch_assoc($Register);
  82. $totalRows_Register = mysqli_num_rows($Register);
  83. ?>
  84. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  85. <html xmlns="http://www.w3.org/1999/xhtml">
  86. <head>
  87. <link href="CSS/layout.css" rel="stylesheet" type="text/css" />
  88. <link href="CSS/menu.css" rel="stylesheet" type="text/css" />
  89. <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
  90. <link href="SpryAssets/SpryValidationPassword.css" rel="stylesheet" type="text/css" />
  91. <link href="SpryAssets/SpryValidationConfirm.css" rel="stylesheet" type="text/css" />
  92. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  93. <title>o-dtr</title>
  94. <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
  95. <script src="SpryAssets/SpryValidationPassword.js" type="text/javascript"></script>
  96. <script src="SpryAssets/SpryValidationConfirm.js" type="text/javascript"></script>
  97. </head>
  98.  
  99. <body>
  100. <div id="Holder">
  101. <div id="Header"></div>
  102. <div id="NavBar">
  103.     <nav>
  104.         <ul>
  105.             <li><a href="Login.php">Login</a></li>
  106.             <li>|</li>
  107.             <li><a href="Register.php"> Register</a></li>
  108.             <li>|</li>
  109.             <li><a href="ForgotPassword.php">Forgot Password</a></li>
  110.         </ul>
  111.     </nav>
  112. </div>
  113. <div id="Content">
  114.   <form id="RegisterForm" name="RegisterForm" method="POST" action="<?php echo $editFormAction; ?>">
  115.     <table width="600" border="0" align="center">
  116.       <tr>
  117.         <td><table border="0">
  118.           <tr>
  119.             <td><span id="sprytextfield1">
  120.               <label for="first_name"></label>
  121.               First Name:<br />
  122.               <input name="first_name" type="text" class="StyleTextField" id="first_name" />
  123.               <span class="textfieldRequiredMsg">A value is required.</span></span></td>
  124.             <td><span id="sprytextfield2">
  125.               <label for="last_name"></label>
  126.               Last Name:<br />
  127.               <input name="last_name" type="text" class="StyleTextField" id="last_name" />
  128.               <span class="textfieldRequiredMsg">A value is required.</span></span></td>
  129.           </tr>
  130.         </table></td>
  131.       </tr>
  132.       <tr>
  133.         <td>&nbsp;</td>
  134.       </tr>
  135.       <tr>
  136.         <td><span id="sprytextfield3">
  137.         <label for="email_address"></label>
  138. Email:<br />
  139. <input name="email_address" type="text" class="StyleTextField" id="email_address" />
  140. <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
  141.       </tr>
  142.       <tr>
  143.         <td>&nbsp;</td>
  144.       </tr>
  145.       <tr>
  146.         <td><table border="0">
  147.           <tr>
  148.             <td><span id="sprypassword1">
  149.               <label for="password"></label>
  150.               Password:<br />
  151.               <input name="password" type="password" class="StyleTextField" id="password" />
  152.               <span class="passwordRequiredMsg">A value is required.</span></span></td>
  153.             <td><span id="spryconfirm1">
  154.               <label for="passwordconfirm"></label>
  155.               Confirm Password:<br />
  156.               <input name="passwordconfirm" type="password" class="StyleTextField" id="passwordconfirm" />
  157.               <span class="confirmRequiredMsg">A value is required.</span><span class="confirmInvalidMsg">The values don't match.</span></span></td>
  158.           </tr>
  159.         </table></td>
  160.       </tr>
  161.       <tr>
  162.         <td>&nbsp;</td>
  163.       </tr>
  164.       <tr>
  165.         <td><input type="submit" name="RegisterButton" id="RegisterButton" value="Register" /></td>
  166.       </tr>
  167.     </table>
  168.     <input type="hidden" name="MM_insert" value="RegisterForm" />
  169.   </form>
  170. </div>
  171. <div id="Footer"></div>
  172. </div>
  173. <script type="text/javascript">
  174. var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
  175. var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
  176. var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "email");
  177. var sprypassword1 = new Spry.Widget.ValidationPassword("sprypassword1");
  178. var spryconfirm1 = new Spry.Widget.ValidationConfirm("spryconfirm1", "password");
  179. </script>
  180. </body>
  181. </html>
  182. <?php
  183. mysql_free_result($Register);
  184. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement