The Mysql code you are using is obsolete and insecure. It has also been removed from Php ver 7. You need to be using PDO with prepared statements or at the least Mysqli.
Your connection code should only be in one place and included where you need it. As is, you need to do updates in three different places if anything changes.
Your code is vulnerable to SQL injection. You are sending user supplied data directly to the database. You should not be using this code at all.
There is also no need to create extra variables on your insert. Additionally, there is no need to close the connection. It is automatically closed after the script runs.