Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. <?php
  2. //salvo dati
  3. $username = $_POST['username'];
  4. $password = $_POST['password'];
  5. $passwordRepeat = $_POST['passwordRepeat'];
  6. $dom=new DOMDocument();
  7. $dom->validateOnParse=true;
  8. libxml_use_internal_errors(true);
  9. $dom->loadHTMLFile("../html/registerUser.html");
  10.  
  11. if($username!=""){
  12. //accesso db
  13. require_once("databaseConnection.php");
  14. //monto query di ricerca
  15. $statementUsernameReserch =("SELECT username FROM accounts WHERE username= '".$username."'");
  16. //eseguo query di ricerca
  17. $checkUsernameQueryResult = mysqli_query($db, $statementUsernameReserch);
  18. $numberRowCheck = mysqli_num_rows($checkUsernameQueryResult);
  19.  
  20. if($numberRowCheck==1){
  21. $findu=$dom->getElementById("errorId");
  22. if(is_object($findu)){
  23. $findu->nodeValue = 'Email gia registrata!!!';
  24. }
  25. echo $dom->saveHTML();
  26. }else if(strlen($password)<8){
  27. $findp=$dom->getElementById("errorPassword");
  28. $findu=$dom->getElementById("username");
  29. if(is_object($findp) && is_object($findu)){
  30. $findp->nodeValue = 'La password deve avere almeno 8 caratteri';
  31. //echo $username;
  32. echo $findu->nodeValue = $username;
  33. echo "pd";
  34. //$findu->nodeValue = $username;
  35. echo $findu->nodeValue;
  36. }
  37. echo $dom->saveHTML();
  38. }else if($passwordRepeat != $password){
  39. $findp=$dom->getElementById("errorPasswordRepeat");
  40. if(is_object($findp)){
  41. $findp->nodeValue = 'Le password non coincidono';
  42. }
  43. echo $dom->saveHTML();
  44. }else{
  45. //altrimenti inserisco
  46. if($numberRowCheck == 0){
  47. $statementInsertUser = ("INSERT INTO accounts (username,password) VALUES ('$username','$password')");
  48. $checkInsertUser = mysqli_query($db,$statementInsertUser);
  49. $numberRowCheck = mysqli_affected_rows($db);
  50.  
  51. if( $numberRowCheck == 1 ){
  52. //nuova pagina con accesso
  53. echo "registrazione ok";
  54. //header("location:../home.html");
  55. }
  56. }
  57. }
  58. // quindi i dati sono stati salvati nel database e l'utente è registrato
  59. mysqli_close($db);
  60. }else{
  61. $find=$dom->getElementById("errorId");
  62. if(is_object($find)){
  63. $find->nodeValue = 'campo obbligatorio';
  64. }
  65. echo $dom->saveHTML();
  66. }
  67.  
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement