Change to mysqli
Move JS to separate file