CODE REFACTORED

Code refactored in order to use mysqli and better error debug.