SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy 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

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,179
    Mentioned
    65 Post(s)
    Tagged
    2 Thread(s)
    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.

  3. #3
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank'x sir for the help it really helped me ...now error is fixed

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    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.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah sir u r write . will u plz tell me what better i thing i can do .

  6. #6
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,179
    Mentioned
    65 Post(s)
    Tagged
    2 Thread(s)
    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.

  7. #7
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok sir thanku


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •