view mackey/academy/add.rb~ @ 2936:af8dd23d5e6a

merged
author GOTO Sakuya <c113061@e.koeki-u.ac.jp>
date Tue, 08 Dec 2015 19:16:08 +0900
parents 2ee6e6efc0dd
children
line wrap: on
line source

#!/usr/bin/env ruby
# coding: euc-jp
require 'rubygems'
require 'pg'
require 'cgi'
c = CGI.new(:accept_charset => "utf-8")
print"Content-type: text/html; charset=utf-8\n\n"

number = c["id"]
pswd = c["pass"]
namae = c["name"]
sx = c["sex"]
check = 0

begin
  conn = PGconn.connect('127.0.0.1','','','','semi','masahiro','l3nl3q1u')
  a = "select id from userdata"
  ip = conn.exec(a)
  ip.each do |row|
    if number == row["id"]
      check = 1 
    end
  end
  if check == 0
    q = "insert into userdata (id, password, name, sex, level, exp, quest) values ('#{number}', '#{pswd}', '#{namae}', '#{sx}', '1', '0', '0')"
    export = conn.exec(q)
  end
end
print"<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
<title>ユーザー登録</title>
<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">
</head>
<body>\n"
if check == 0
  print"<h1>登録完了</h1>
<a href=\"login.html\">
<button class=\"css3button\">ログイン</button>\n"
elsif check == 1
  print"<h1>Error</h1>
<p>既にIDが使われています</p>
<a href=\"add.html\">
<button class=\"css3button\">もう一度</button>\n"
end
print"</a>
</body>
</html>\n"

yatex.org