Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. <?php
  2.  
  3. include_once "mmoconnection.php";
  4.  
  5. $mydata = json_decode(file_get_contents('php://input'));
  6.  
  7. $accountname = $mydata ->accountname;
  8. $username = $mydata ->username;
  9. $accountpassword = $mydata ->accountpassword;
  10.  
  11. if ($stmt = $conn->prepare("SELECT * FROM `users` WHERE accountname = ? "))
  12. {
  13. $stmt->bind_param("s", $accountname);
  14. $stmt->execute();
  15. if ($stmt->fetch()) echo json_encode(array('status'=>'This account name is unavailable')); // IF ACOUNT NAME IS TAKEN THEN BAD STATUS
  16. else{
  17.  
  18. if ($stmt = $conn->prepare("SELECT * FROM `characters` WHERE username = ? "))
  19. {
  20. $stmt->bind_param("s", $username);
  21. $stmt->execute();
  22. if ($stmt->fetch()) echo json_encode(array('status'=>'This user name is unavailable')); // IF USER NAME IS TAKEN THEN BAD STATUS
  23. else {
  24. // CREATE ACCOUNT
  25. $hash = password_hash($accountpassword, PASSWORD_DEFAULT);
  26. $stmt = $conn->prepare("INSERT INTO `users` VALUES (NULL, ?, ?)");
  27. $stmt->bind_param("ss", $accountname, $hash);
  28. $stmt->execute();
  29. $stmt = $conn->prepare("INSERT INTO `characters` VALUES (NULL, NULL, ?, NULL)");
  30. $stmt->bind_param("s", $username);
  31. $stmt->execute();
  32.  
  33. $stmt->close();
  34.  
  35. echo json_encode(array('status'=>'OK' ));
  36. }
  37. }
  38. }
  39. }
  40. ///'EXPLAIN SELECT * FROM `characters`';
  41.  
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement