Undefined index: Cookie (NOT POSIBLE?)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

Undefined index: Cookie (NOT POSIBLE?)

Post by yosuke_ »

Hi!
I have Login.htm and Login.php pages. Login.htm Look like this:

Code: Select all

</head>

<body>
<form name="form1" method="post" action="login.php">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <table width="212" border="0" align="center" cellpadding="2" cellspacing="0" bordercolor="#F3F3F3" class="style2">
    <tr bgcolor="#F3F3F3">
      <td width="79" bgcolor="#F3F3F3"><div align="right"><span class="style4">username:</span></div></td>
      <td width="153"><input name="txtusername" type="text" class="style2" id="txtusername"></td>
    </tr>
    <tr bgcolor="#F3F3F3">
      <td bgcolor="#F3F3F3"><div align="right"><span class="style4">password:</span></div></td>
      <td><input name="txtpassword" type="password" class="style2" id="txtpassword"></td>
    </tr>
    <tr bgcolor="#F3F3F3">
      <td bgcolor="#F3F3F3"><div align="right">
        <input name="Cookie" type="checkbox" class="style2" id="Cookie" value="True" checked>
      </div></td>
      <td>Give me a cookie </td>
    </tr>
    <tr bgcolor="#F3F3F3">
      <td>&nbsp;</td>
      <td><input type="image" value="submit" img src="Images/login.bmp"></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
</body>
</html>
I have one checkbox named Cookie and it hase value True and it is checked by default, but the problem is this: When I uncheck it and click login, I get error: Notice: Undefined index: Cookie in c:\inetpub\wwwroot\login.php on line 5
Why does it looses index when I uncheck it?? what is wrong?? I just request it from Login.php like this: $set_cookie = $_POST["Cookie"];
Thank You!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

unchecked checkboxes aren't posted.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Yeah, if the checkbox isnt checked then its not posted so when you check or echo a variable that hasnt been sent you get that message.

All you need to do is do isset($var) beforehand and you wont get the error if the box hasnt been checked.
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

Post by yosuke_ »

I still have the same error!! Here is my code for Login.php

Code: Select all

<?php
$set_cookie = $_POST["Cookie"];
if (isset($set_cookie))
{
echo "Cookie is set";
}
else
{
echo "Cookie not set";
}
?>
I get this error:

Notice: Undefined index: Cookie in c:\inetpub\wwwroot\login.php on line 1
Cookie not set

The code works and it displays that cookie is not set but I still get that error!! HEEELPP!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

if(isset($_POST&#1111;'Cookie']))
 $set_cookie = $_POST&#1111;'Cookie'];
else
 $set_cookie = null;
or something similar.
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

Post by yosuke_ »

Thank you very much!! it works!!!
Post Reply