Advertisement
Guest User

Untitled

a guest
Mar 6th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4.  
  5. <style type="text/css">
  6.  
  7. .error{
  8. color: red;
  9. }
  10. input::-webkit-outer-spin-button,
  11. input::-webkit-inner-spin-button {
  12.  
  13. -webkit-appearance: none;
  14. margin: 0;
  15. }
  16. }
  17. </style>
  18.  
  19. <meta charset="utf-8">
  20. <title>Register</title>
  21.  
  22. <?php
  23. session_start();
  24. $action=$_SERVER["PHP_SELF"];
  25. $errors= array( "", "", "", "", "", "" );
  26. $_SESSION['errors'] = $errors; // nomeErr, cognomeErr, emailErr, cod_fisErr, passwordErr, c_passwordErr
  27. $Nome = $indirizzo = $Cognome = $email = $c_password = $password = $CAP = $Città = $cod_fis ="";
  28.  
  29.  
  30.  
  31. $servername = "localhost";
  32. $username = "Concessionario";
  33. $passwordDB = "rUC1TqQK9wfbShVs";
  34.  
  35. $conn = new mysqli($servername, $username, $passwordDB);
  36.  
  37. $condition = true;
  38. if ($conn->connect_error) {
  39. die("Connection failed: " . $conn->connect_error);
  40. }
  41.  
  42.  
  43. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  44. ////////////////////////////
  45. if (empty($_POST["Nome"])) {
  46. $_SESSION['errors'][0] = "Nome è obbligatorio";
  47.  
  48.  
  49. } else {
  50. $Nome = test_input($_POST["Nome"]);
  51.  
  52. if (!preg_match("/^[a-zA-Z ]*$/",$Nome)) {
  53.  
  54. $_SESSION['errors'][0] = "Solo spazi bianchi e lettere sono ammessi";
  55.  
  56. }
  57. }
  58. ////////////////////////////
  59.  
  60. if (empty($_POST["CAP"])) {
  61.  
  62. $CAPErr = "CAP è obbligatorio";
  63.  
  64. } else {
  65. $CAP = ($_POST["CAP"]);
  66. }
  67.  
  68.  
  69. ///////////////////////////
  70. if (empty($_POST["Cognome"])) {
  71.  
  72. $_SESSION['errors'][1] = "Cognome è obbligatorio";
  73. } else {
  74. $Cognome = test_input($_POST["Cognome"]);
  75.  
  76. if (!preg_match("/^[a-zA-Z ]*$/",$Cognome)) {
  77.  
  78. $_SESSION['errors'][1] = "Solo spazi bianchi e lettere sono ammessi";
  79. }
  80. }
  81. //////////////////////////
  82. if (empty($_POST["email"])) {
  83.  
  84. $_SESSION['errors'][2] = "Email è obbligatorio";
  85.  
  86. } else {
  87. $email = test_input($_POST["email"]);
  88.  
  89. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  90.  
  91. $_SESSION['errors'][2] = "Formato E-Mail non valido";
  92. }
  93. }
  94. ////////////////////////////
  95.  
  96. if (empty($_POST["cod_fis"]))
  97. $_SESSION['errors'][3] = "Il codice fiscale è obbligatorio";
  98. else if (strlen($cod_fis=($_POST["cod_fis"])) < 16) $_SESSION['errors'][3] = "Codice fiscale non valido";
  99. else
  100. $cod_fis=($_POST["cod_fis"]);
  101. ////////////////////////////
  102. if (empty($_POST["password"])) {
  103.  
  104. $_SESSION['errors'][4]= "Password è obbligatorio";
  105. }
  106. elseif (empty($_POST["c_password"])) {
  107.  
  108. $_SESSION['errors'][5]= "Conferma Password è obbligatorio";
  109. }
  110. else{
  111. if($_POST["c_password"] != $_POST["password"] ){
  112.  
  113. $_SESSION['errors'][5]="Le due Password non corrispondono";
  114. }
  115. else{
  116. $password=test_input($_POST["password"]);
  117.  
  118. }
  119. }
  120.  
  121. if (empty($_POST["Città"])) {
  122.  
  123. $errors['CittàErr'] = "Città è obbligatorio";
  124.  
  125. } else {
  126. $Città = test_input($_POST["Città"]);
  127.  
  128. if (!preg_match("/^[a-zA-Z ]*$/",$Città)) {
  129.  
  130. $errors['CittàErr'] = "Solo spazi bianchi e lettere sono ammessi";
  131. }
  132. }
  133.  
  134. $provincia = $_POST['Provincia'];
  135. $indirizzo = $_POST["indirizzo"];
  136.  
  137.  
  138.  
  139. /*if (isset($provincia)) {
  140. //Fix Default selected
  141. }
  142. */
  143. }
  144.  
  145.  
  146.  
  147. function test_error(){
  148. if (isset($_POST['Submit'])){
  149. foreach($_SESSION['errors'] as $x => $x_value) {
  150. if ($x_value != "") {
  151. $action=$_SERVER["PHP_SELF"];
  152. break;
  153. }
  154. }
  155. $action="try.php";
  156. }
  157. }
  158.  
  159. function test_input($data) {
  160. $data = trim($data);
  161. $data = stripslashes($data);
  162. $data = htmlspecialchars($data);
  163. return $data;
  164. }
  165.  
  166. ?>
  167.  
  168. </head>
  169.  
  170. <body>
  171.  
  172.  
  173.  
  174. <form method="post" id="login" action="<?php test_error(); echo htmlspecialchars($action);?>">
  175.  
  176. Nome: <input type="text" maxlength="30" name="Nome" value="<?php echo $Nome; ?>">
  177. <span class="error"> <?php echo $_SESSION['errors'][0];?></span>
  178. <br><br>
  179. Cognome: <input type="text" maxlength="30" name="Cognome" value="<?php echo $Cognome; ?>">
  180. <span class="error"> <?php echo $_SESSION['errors'][1];?></span>
  181. <br><br>
  182. E-Mail: <input type="text" maxlength="40" name="email" value="<?php echo $email; ?>">
  183. <span class="error"> <?php echo $_SESSION['errors'][2];?></span>
  184. <br><br>
  185. Codice Fiscale: <input type="text" maxlength="16" name="cod_fis" value="<?php echo $cod_fis; ?>">
  186. <span class="error"> <?php echo $_SESSION['errors'][3];?></span>
  187. <br><br>
  188. Password: <input type="password" maxlength="32" name="password" value="<?php echo $password; ?>">
  189. <span class="error"> <?php echo $_SESSION['errors'][4];?></span>
  190. <br><br>
  191. Conferma Password: <input type="password" maxlength="32" name="c_password" value="<?php echo $c_password; ?>">
  192. <span class="error"> <?php echo $_SESSION['errors'][5];?></span>
  193. <br><br>
  194. Indirizzo: <input type="text" maxlength="50" name="indirizzo" value="<?php echo $indirizzo; ?>">
  195. <br><br>
  196. CAP: <input type="number" name="CAP" maxlength="10" value="<?php echo $CAP; ?>">
  197. <br><br>
  198. Città: <input type="text" name="Città" maxlength="30" value="<?php echo $Città; ?>">
  199. <br><br>
  200. Provincia <select name="Provincia">
  201. <?php
  202. $prov=file("Province.txt");
  203. for ($i=0; $i<sizeof($prov); $i++) {
  204. $item=explode('|',$prov[$i]);
  205. echo "<option value='".$item[0]."'> ".$item[0]."</option>";
  206. }
  207. ?>
  208. </select>
  209. <br><br>
  210. <input type="submit" name="Submit" value="Invia"> <input type="reset" name="Reset" value="Reset"> <!--Reset or reload? -->
  211. </form>
  212.  
  213.  
  214.  
  215. </body>
  216. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement