Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //salvo dati
- $username = $_POST['username'];
- $password = $_POST['password'];
- $passwordRepeat = $_POST['passwordRepeat'];
- $dom=new DOMDocument();
- $dom->validateOnParse=true;
- libxml_use_internal_errors(true);
- $dom->loadHTMLFile("../html/registerUser.html");
- if($username!=""){
- //accesso db
- require_once("databaseConnection.php");
- //monto query di ricerca
- $statementUsernameReserch =("SELECT username FROM accounts WHERE username= '".$username."'");
- //eseguo query di ricerca
- $checkUsernameQueryResult = mysqli_query($db, $statementUsernameReserch);
- $numberRowCheck = mysqli_num_rows($checkUsernameQueryResult);
- if($numberRowCheck==1){
- $findu=$dom->getElementById("errorId");
- if(is_object($findu)){
- $findu->nodeValue = 'Email gia registrata!!!';
- }
- echo $dom->saveHTML();
- }else if(strlen($password)<8){
- $findp=$dom->getElementById("errorPassword");
- $findu=$dom->getElementById("username");
- if(is_object($findp) && is_object($findu)){
- $findp->nodeValue = 'La password deve avere almeno 8 caratteri';
- //echo $username;
- echo $findu->nodeValue = $username;
- echo "pd";
- //$findu->nodeValue = $username;
- echo $findu->nodeValue;
- }
- echo $dom->saveHTML();
- }else if($passwordRepeat != $password){
- $findp=$dom->getElementById("errorPasswordRepeat");
- if(is_object($findp)){
- $findp->nodeValue = 'Le password non coincidono';
- }
- echo $dom->saveHTML();
- }else{
- //altrimenti inserisco
- if($numberRowCheck == 0){
- $statementInsertUser = ("INSERT INTO accounts (username,password) VALUES ('$username','$password')");
- $checkInsertUser = mysqli_query($db,$statementInsertUser);
- $numberRowCheck = mysqli_affected_rows($db);
- if( $numberRowCheck == 1 ){
- //nuova pagina con accesso
- echo "registrazione ok";
- //header("location:../home.html");
- }
- }
- }
- // quindi i dati sono stati salvati nel database e l'utente è registrato
- mysqli_close($db);
- }else{
- $find=$dom->getElementById("errorId");
- if(is_object($find)){
- $find->nodeValue = 'campo obbligatorio';
- }
- echo $dom->saveHTML();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement