Your web-users only access your PHP script, and your PHP script connects to your database.
the 'localhost' is the machine itself, you can only use that if you want to connect your PHP script to a databae server that is running on the same machine. Otherwise you'll have to change the hostname in PHP to the hostname of the machine that is running the MySQL. Change MySQL's access rights if neccecary. (read about the GRANT statement, forget all about changing the user tables manually)