Use php tags instead of code tags when posting php code on this board. Also, always indent your code or it's unreadable.
session_start();
if(!isset($_SESSION['counter']))
{
# You want to use an integer, but supply a string. It will work since php to
# automatic typecasting, but if you are using a variable as an integer,
# I recommend assigning it an integer (drop the single quotes)
$_SESSION['counter'] = 1;
}
# The first time you display the page (by inputting url in address field or clicking a link)
# there is no post data, which means this part is not executed, and it should instead
# be
if(isset($_POST['name']))
{
# You only ever use $_SESSION['display'] on the next line to echo its contents
# so why bother storing it?
echo '<div id="id'.$_SESSION['counter'].'">'.$_POST['name'].'</div>';
# But if you do store it as you did, then the echo goes here, not outside
# the if block where this element may be undefined.
}
# Which means that you will get an error here: Notice: undefined index 'display'
# echo $_SESSION['display'];
$_SESSION['counter']++;
# reset is a constant, and since you have not defined it:
# Notice: Use of undefined constant reset, assumed 'reset'
# which means that PHP will define it and assign it the value 'reset', which is why your code
# "works". I'm not saying works, since there is indeed an error in there, and if you ever do
# define a constant named reset, you will most likely have non-working code for no obvious
# reason. Always display (not in production environment) / log all errors, including notices,
# and always fix them. Here, add single quotes
if($_POST['reset'])
{
# To unset an entire array, unset($_SESSION), not unset($_SESSION[]).
# If you want to unset a null/empty string element (they are the same), use
# unset($_SESSION['']) or unset($_SESSION[null])
unset($_SESSION);
}