Why this maximum time this undefined index error occurs

Notice: Undefined index: username in C:\wamp\www\advance php\submit.php on line 13

<?php
if(isset($_POST[‘clientname’]))
{
$client=$_POST[‘clientname’];
setcookie(‘username’,$client,time()+120);
}
?>
<html>
<head>
<title>submit page</title>
</head>
<body>
<h1>Thank’s Mr.<?php echo $_COOKIE[‘username’]; ?> For the intrest we will get back to u soon</h1>
</body>
</html>

please tell me why its happening …help me out

At the beginning of the script, do var_dump($_POST); to see if clientname is present and that you are actually setting the cookie.

Side note, use sessions over cookies whenever you can.

Thank’x sir for the help it really helped me …now error is fixed :slight_smile:

Just for information and future reference;
A cookie can’t be set and then used on the same page. You would need to refresh the page before the cookie is set and readable.

yeah sir u r write . will u plz tell me what better i thing i can do .

Sessions. http://php.net/manual/en/ref.session.php. They are more secure anyway as they are stored on the server rather than on the client machine.

ok sir thanku