I've only just started to learn about php, and I have used code from a tutorial (below). When the form is filled out and submitted, the form is again displayed (not the message intended). It appears that the $submit variable isn't being recognised so it displays the form again. I have managed to get this working by other methods , but I can't get this to work. Here is the code:
<html>
<body>
<?php
if ($submit) {
// process form
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$sql = "INSERT INTO employees (first,last,address,position) VALUES ('{$POST['first']}','{$POST['last']}','{$POST['address']}','{$POST['position']}')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
} else{
// display form
?>
<form method="post" action="<?php echo $PHP_SELF?>">
First name:<input type="Text" name="first"><br>
Last name:<input type="Text" name="last"><br>
Address:<input type="Text" name="address"><br>
Position:<input type="Text" name="position"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
} // end if
?>
</body>
</html>
Help would be greatly appreciated.