There are a few options available to you:
- Validate the form post data before inserting into the database
- Include a nonce or other generated value that is only present in the form prior to submission
The problem you're trying to solve really sounds like you want to prohibit blank records from being inserted into the database- not necessarily that you want to prevent access to add.php. This is where option #1 comes into play.
In your current add.php, it sounds like there needs to be some input validation. Basically, you'd check the values that are received by the script to make sure they exist. For example, if add.php accepts a first name, as part of a phonebook app, you'd have code similar to the below:
$firstName = '';
if(isset($_GET['firstName']))
$firstName = $isset($_GET['firstName']);
// ...
if(trim($firstName) == '')
//do something to handle an error, either set an error flag or die() with an appropriate message
This is a basic example of input validation, PHP has a validation library you may want to become familiar with: http://www.php.net/manual/en/intro.filter.php
With this input validation in place, someone can navigate to add.php and should receive an error. It will also detect if someone submits a blank form as well.
#2 requires that your form receive a unique value when it's generated called a nonce. The nonce is a unique value that's specific to that instance of the form. The subsequent call to add.php will only accept the request if the nonce is valid. An approach might be to store the nonce in the user's session.
Another note outside the scope of the question, since you're inserting data into a database, you should make sure you have proper escaping of inserted data. If you're using MySQL, see here: http://www.php.net/manual/en/mysqli.real-escape-string.php. If using another database engine, you'll want to lookup the specific library to see how to escape the string.