I am concerned that someone could create their own PHP or HTML form and POST to MY 2nd PHP file and submit any values to my database.
They can, and they don't even need to go to the trouble of creating an HTML page to do it.
Is this the proper way to secure input to the database?
The correct way of doing this is to never allow inputs to specify table or column names (or any SQL identifier). Inputs should only specify column values or values used in comparisons in WHERE clauses.
Enumerate the queries you need, and come up with a way to let the form specify the particular query you want and make sure you properly authenticate for that particular query.
If you are trying to do ad-hoc reporting, explicitly design for that. Open Source & Free Adhoc / End User Reporting Tool addresses that for PHP.
"ad hoc" reporting systems allow the users themselves to create specific, customized queries.
Ad-hoc reporting is tough to do securely because many SQL-security best practices like prepared statements do not allow parameterizing queries with table names, and there are often corner cases to ad-hoc reporting that leak PII that are not otherwise available.
I want to put the username, password, ... on the 1st PHP page (with the form) and pass these as variables to the 2nd PHP form
It's not clear from your question that you're doing this, but just to be clear, you should never export the database username and password or allow form inputs to affect your database connection configuration. This makes it far easier for an attacker to
- covert the ability to run a low-power shell inside your firewall into a partial takeover of your database,
- brute force your database's administrative password given only web access and time and then turn any SQL injection flaw into a complete takeover of your database.