how to check uniqueness of a username in MySQL database via JSON? -
i have next page, on user can create new account. question how can make sure user inserts username doesn't exist in mysql database. page available on http://webs.hogent.be/kevinbaeyens/gebruiker.html code of page is:
<!doctype html> <html class=""> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>nieuwe gebruiker | sociale buurt</title> <link href="boilerplate.css" rel="stylesheet" type="text/css"> <link href="onzebuurt.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="jquery-1.7.1.min.js"></script> <script type="text/javascript" language="javascript"> window.onload = function() { document.getelementbyid("username").focus(); }; function formuliervalideren() { if (document.getelementbyid('username').value == '' || document.getelementbyid('username').value == null) { alert ('gebruikersnaam verplicht.'); document.getelementbyid('username').style.bordercolor = "red"; return false; } else if (document.getelementbyid('wachtwoord').value == '' || document.getelementbyid('wachtwoord').value == null) { alert ('wachtwoord verplicht.'); document.getelementbyid('wachtwoord').style.bordercolor = "red"; return false; } else if (document.getelementbyid('wachtwoord2').value == '' || document.getelementbyid('wachtwoord2').value == null) { alert ('bevestig wachtwoord.'); document.getelementbyid('wachtwoord2').style.bordercolor = "red"; return false; } else if (document.getelementbyid('wachtwoord2').value != document.getelementbyid('wachtwoord').value) { alert ('wachtwoorden komen niet overeen.'); document.getelementbyid('wachtwoord2').style.bordercolor = "red"; return false; } else { var url = "http://localhost:8080/onzebuurt2/resources/gebruikers"; var reminder = {}; reminder.naam = jquery.trim($("#username").val()); reminder.wachtwoord = jquery.trim($("#wachtwoord").val()); var request = new xmlhttprequest(); request.open("post", url); request.onload = function() { if (request.status === 201) { reminder.id = request.getresponseheader("location").split("/").pop(); } else { console.log("error creating reminder: " + request.status + " " + request.responsetext); } }; request.setrequestheader("content-type", "application/json"); request.send(json.stringify(reminder)); var msg = "registratie succesvol. klik op ok om u aan te melden op de site."; if(confirm(msg)){ settimeout(function() {window.location.href = "http://localhost:8080/onzebuurt2/"}) } } //end if }//end function </script> </head> <body class="body2"> <div class="gridcontainer clearfix"> <div class="header2"> <center> nieuwe gebruiker </center> </div> <div id="formulier2"> <form method="post" name="form" action=""> <p class="labels"><center>gebruikersnaam *</center></p><input id="username" type="text" name="username" placeholder="gebruikersnaam" size="50"> <p class="labels"><center>wachtwoord *</center></p><input id="wachtwoord" type="password" name="wachtwoord" placeholder="wachtwoord" size="50"> <p class="labels"><center>bevestig wachtwoord *</center></p><input id="wachtwoord2" type="password" name="bevestig wachtwoord" placeholder="bevestig wachtwoord" size="50"> <br /> <a href="index.html" style="text-decoration:none"><center><img id="return" name="jsbutton" src="return.png" alt="terug" /></center></a> <br /> <center><input id="bevestig" type="image" src="bevestig.png" width="200" height="50" border="0" alt="submit!" onclick="formuliervalideren()"></center> <br /> </form> </div> </div> </body> </html>
some notes need know:
1) since it's assignment school, can't use php.
2) primary key in database table 'gebruiker' 'id', field of 'username' field has unique
thanks in advance!
Comments
Post a Comment