automatic updates – is it right choose to connect database in template page directly in WordPress site?

i’m a little bit new in WordPress and for now working on WordPress site that some information will insert to database from forms … i design some page template and use mysqli_connect() to connect database and mysqli_query() to insert data to database .

the question i wonder is , am i do mistake ? is it possible that pages or piece of database erase after WordPress updates or totaly Could something bad happen? should change anything or not ?

i will thanks to anyone that help me. 🙂