php - Error "Undefined index" if check box is not checked -


when check checkbox there no errors, when didn't check checkbox gives me errors.

 <?php     if(isset($_request['btn']))     {         $remmber = $_request['active'];     if($remmber == "on")         {               echo "checked";         }         else  {$remmber = "";}     }     ?>     <html>     <form name= "frm" action = "test.php" method = "post" >     <p>username     <input  type = "text" name = "name" value = ""  />     </p>      <p>password     <input type = "text" name = "password" value = "" />     </p>      <p>     <td colspan = "2"><input type = "checkbox" name = "active" value = "active" />keep me loged in      </p>      <p><input type = "submit" name = "btn" value = "login" />      </p>       </form>     </html> 

for checkboxes if not checked not posted. check if present in posted data set on, else set blank variable. try -

if(isset($_request['btn'])) {     $remmber = !empty($_request['active']) ? 'on' : '';     if($remmber == "on")     {           echo "checked";     }     else          $remmber = ""; } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -