Guest User

Untitled

a guest
Oct 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?php
  2. $connect = mysqli_connect("localhost", "id3199319_kbcmaster", "xplayers2305", "id3199319_kbcregistration");
  3.  
  4. $name = $_POST["name"];
  5. $time = $_POST["time"];
  6. $id = $_POST["id"];
  7.  
  8. function registerUser() {
  9. global $connect, $name, $time, $id;
  10. $statement = mysqli_prepare($connect, "INSERT INTO registration (name, time, id) VALUES (?, ?, ?)");
  11. mysqli_stmt_bind_param($statement, "sss", $name, $time, $id);
  12. mysqli_stmt_execute($statement);
  13. mysqli_stmt_close($statement);
  14. }
  15. function nameAvailable() {
  16. global $connect, $id;
  17. $statement = mysqli_prepare($connect, "SELECT * FROM registration WHERE id = ?");
  18. mysqli_stmt_bind_param($statement, "s", $id);
  19. mysqli_stmt_execute($statement);
  20. mysqli_stmt_store_result($statement);
  21. $count = mysqli_stmt_num_rows($statement);
  22. mysqli_stmt_close($statement);
  23. if ($count < 1){
  24. return true;
  25. }else {
  26.  
  27. // Logic needs to be here as per requirement maybe
  28.  
  29. return false;
  30. }
  31. }
  32. $response = array();
  33. $response["success"] = false;
  34. if (nameAvailable()){
  35. registerUser();
  36. $response["success"] = true;
  37. }
  38.  
  39. echo json_encode($response);
  40. ?>
Add Comment
Please, Sign In to add comment