Advertisement
IcaroPeretti

rackey

Apr 26th, 2022 (edited)
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #lang racket
  2.  
  3. (require web-server/servlet
  4. web-server/servlet-env)
  5. (require net/uri-codec)
  6.  
  7. (require db)
  8. (define pgc
  9. (mysql-connect #:user "root"
  10. #:password "root"
  11. #:database "worldcup"
  12. #:server "localhost" )
  13. )
  14.  
  15. (define (world-cup req)
  16.  
  17. (define uri(request-uri req))
  18.  
  19. (define path (map path/param-path (url-path uri)))
  20.  
  21. (define page (car path ))
  22.  
  23. (cond
  24. [(equal? page "index") ; pagina 1
  25.  
  26. (response/xexpr
  27. `(html
  28. (head (title "World Cup Simulation - Icaro e Eduardo"))
  29. (body (center(h1 "World Cup Simulation")
  30. (center(h3 "Programação Lógica e Funcional"))
  31. (p "Alunos: Ícaro Peretti e Eduardo Rampon Meireles")
  32. (center(h2 "Cadastro de times"))
  33. ;envia os dados do form via post para a pagina de registro
  34. (form ([method "POST"] [action "/register-team"])
  35. "Nome do time: " (input ([type "text"] [name "nome"]))
  36. (br)
  37. (br)
  38. (input ([type "submit"] [value "Cadastrar"])))))))]
  39.  
  40. [(equal? page "register-team")
  41.  
  42. (define post-data (bytes->string/utf-8 (request-post-data/raw req)))
  43.  
  44. ; convert to an alist:
  45. (define form-data (form-urlencoded->alist post-data))
  46.  
  47. ; pull out the team name:
  48. (define teamName (cdr (assq 'nome form-data)))
  49.  
  50.  
  51. ; insert to database:
  52. (query-exec pgc
  53. "insert into teams (nome) values (?)"
  54. (list teamName))
  55.  
  56.  
  57.  
  58.  
  59. (response/xexpr
  60. `(html
  61. (body
  62. (p "Your team name is: " ,teamName)
  63. )))]
  64. )
  65.  
  66. )
  67.  
  68.  
  69.  
  70. (serve/servlet world-cup
  71. #:servlet-path "/index"
  72. #:port 8001 ;porta que a pagina ira rodar
  73. #:servlet-regexp #rx""
  74. )
  75.  
Advertisement
RAW Paste Data Copied
Advertisement