adddata.php has a form which allows a user to submit certain data to the database however each time the page loads or is refreshed, the empty form is submitted (creating a row of blank values in the DB).

I have little experience with PHP so apologies in advance for any novice mistakes - here is the code:

Consider using a PHP MVC framework instead of writing spaghetti code, since it will make your life a whole lot easier in the long run. Examples of PHP MVC frameworks: Symfony, Zend Framework, Cake PHP and many others.
–
ridOct 8 '11 at 22:02

mysql_real_escape_string will help prevent SQL injection attacks being carried out against your website.

EDIT

If I understand you right you also need to check to see if a form has actually been submitted before running your database statement, at the moment you're running it regardless of whether or not the form has been submitted. Move all of your PHP code from the bottom of the document inside the if(isset($_POST['submit'])) statement at the top, that should sort it out.

if(isset($_POST['submit'])) {
$name = $_POST['address_v4'];
echo "Successful submitted";
// Now the code from the bottom, minus the database file include as you've already got that further up in the code
$address=isset($_POST['address_v4']) ? mysql_real_escape_string($_POST['address_v4']) : '';
// ...

I've moved the code from the bottom into the isset() statement as per your comment - the form is no longer submitting on page load, however it no longer submits when I enter data in the form normally
–
BernardOct 8 '11 at 23:46

Have got it working now - had missed out "mysql_query($sql) or die(mysql_error());" and looks like its working :) thanks
–
BernardOct 8 '11 at 23:59

isset() checks if a value is set or not and returns true or false. Change that to something like:

if (isset($_POST['address_v4']))
{
// if the value does indeed exist, then prepare it to be used in an SQL query
// and assign it to the $address variable
$address = mysql_real_escape_string($_POST['address_v4']);
}
else
{
// if the value does not exist, then make the $address variable an
// empty string
$address = '';
}

Hi Radu, thanks very much for your input. I've tried this method as well as Clive's and neither seem to be stopping the form from submitting the blank data. Do you have any other suggestions?
–
BernardOct 8 '11 at 23:11

$tbl_name = "addresses"; and the name of the file is adddata.php
–
BernardOct 8 '11 at 23:27