How to use $wpdb (from the template) to update the DB, without being an admin

It seems like you’re trying to use $wpdb without first declaring the global $wpdb. You should not need to enqueue admin.php in order to use $wpdb.

add:

global $wpdb;

to the top of your function instead.

If you’re trying to run code in a file without passing it via wordpress (i.e. you’re just navigating to /somefile.php) make sure you include wp-load.php (although this is NOT best practice).

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)