I have this code from another Stack Overflow question answered here.
I have a mysql table called track in my database.
$server = "host";
$username = "user";
$password = "pass";
$database = "database";
$connId = mysql_connect($server,$username,$password) or die("Cannot connect to server");
$selectDb = mysql_select_db($database,$connId) or die("Cannot connect to database");
$host_name = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$strSQL = "INSERT INTO track (tm, ref, agent, ip, tracking_page_name, host_name) VALUES(curdate(),'$ref','$agent','$ip','$tracking_page_name','$host_name')";
userhas read permissions but not write permissions on the database or the table, read ops will succeed but write ops will fail.
It will show you why the operation failed (docs).
Also, if you're starting don't use
MySQL functions. They are being removed from PHP so you're just giving yourself more work to do in the future. Use
PDO_MySQL instead (docs).
Finally, never just insert text you got from the browser in an SQL query. The values of
$_SERVER['HTTP_USER_AGENT'] can be manipulated by your user to be anything, including a string that causes you to execute whatever query the user wants (delete your tables, exfiltrate your data...). Learn about prepared statements and parameterized queries and use them instead