Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- $db = new PDO("mysql:host=localhost;dbname=gamesite",
- "root","root");
- if (isset ($_POST['newlogin'])){
- $newpassword = $_POST['newpassword'];
- $newusername = $_POST['newusername'];
- $query = $db->prepare("INSERT INTO users(username, password)
- VALUES(:username, :password )");
- $query->bindParam("username", $newusername);
- $query->bindParam("password", $newpassword);
- $checkquery = $db->prepare("SELECT username FROM users WHERE username='$newusername'");
- $checkquery->execute();
- $result = $checkquery -> fetchAll(PDO::FETCH_ASSOC);
- if($result->num_rows > 0){
- echo "Username already exists";
- }
- else{
- $query->execute();
- echo "Account created, you can login now";
- }
- }
- } catch(PDOException $e) {
- die("Error: " . $e->getMessage());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement