Calculate sum of field using stackapps

Tried taking a different track by inserting html/php code stack

I can get it to connect to the database using the code below

<?php $dbhost = 'localhost:3306'; $dbuser = '*******'; $dbpass = '*********' ; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if (! $conn ) { die('could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($conn); ?>

This works and displays the text ‘Connected successfully’

but as i have next to no php knowledge i tried the code

<?php $dbhost = 'localhost:3306'; $dbuser = '********'; $dbpass = '*********' ; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if (! $conn ) { die('could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql> SELECT SUM(inventory_value) -> FROM inventory WHERE student = session(userid) AND sub_category = "safety" mysql_close($conn); ?>

but it crashed, being php I hope this would be an easy answer fro someone now