<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>greetings with count</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
</head>
<body>

<!-- php form that calls up itself ! -->

<?php

if($_GET['fullname']) {
  $name=$_GET['fullname'];
  print "<p> hello $name</p>";

  // open mysql connection

  $link=mysqli_connect('localhost','test','');
  if(! $link) {
    print "<p>At this time, I can not tell you how many times you have been greeted.</p>";
  }
  else {
    mysqli_select_db($link,'test');
    $query="SELECT * FROM greetings WHERE name='$name'";
    #print "my query is $query<br/>";
    $result=mysqli_query($link,$query);
    $error=mysqli_error($link);
    if($error) {
      print "mysql error: $error<br/>\n";
    }
    if(! mysqli_num_rows($result)) {
      print "<p>This is my first greeting to you!</p>";
      $number=1;
      $query="INSERT INTO greetings VALUES  ('$name','$number')";
      #print "my query is $query<br/>";
      $result=mysqli_query($link,$query);
      $error=mysqli_error($link);
      if($error) {
	print "mysql error: $error<br/>\n";
      }
    }
    else {
      $columns=mysqli_fetch_array($result);
      $number=$columns['number']+1;
      $query="UPDATE greetings SET number='$number' WHERE name='$name'";
      $result=mysqli_query($link,$query);
      $error=mysqli_error($link);
      if($error) {
	print "mysql error: $error<br/>\n";
      }
      print "<p>This is greeting number $number</p>\n";
    }
  }
}

print "<form action=\"$_SERVER[PHP_SELF]\" method=\"get\">\n";
print "<p><label for=\"fullname\">your name</label>
  <input id=\"fullname\" value=\"$_GET[fullname]\" 
  name=\"fullname\"/></p>";
print "</form>\n";
?>

<p id="validator">
<a href="http://validator.w3.org/check?uri=referer"><img
    style="border: 0pt"
    src="http://dlib.info/valid-xhtml10.png"
    alt="Valid XHTML 1.0!" height="31" width="88" /></a>
</p>
</body>
</html>

Valid XHTML 1.0!