You're absolutely bankers sure that this sentence is ok?
$sql = "INSERT INTO referer (ip, date, referer, browser) VALUES ('$ip', '$date', '$ref', '$brw')";
I mean that all fields in db exists, have correct names and so on?
If not, I can't see any other possibility than that your mysql-user don't have the right grants.
Don't consider that very likely, but... 😉
It did work on the refresh?
What other code do you have on the page?
knutm