Results 1 to 10 of 10

Thread: checkboxes and php

  1. #1
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default checkboxes and php

    if in a form we have
    Code:
    <label>
          <input name="remember" type="checkbox" id="remember" value="yes" />
          Remember me?</label>
    then the php handler refers to this var as

    $VALUE=$_POST['remember'];

    CHECKED checkbox will give $VALUE="yes" and UNCHECKED checkbox will give $VALUE="" ? CORRECT ?

  2. #2
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    No. If it is not checked, it won't even be send to the server for processing.

    To see if a checkbox has been checked, the simple method I use it:
    PHP Code:
    $has_checkbox_been_checked = isset($_POST['remember']); //returns a boolean 

  3. #3
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    is it wrong the

    remember=checkbox
    Code:
      if ($_POST['remember'] == "yes") {
    	  $remember = $_SESSION["email"];
    	  setcookie("remember", $remember, time()+60*60*24*365);    //  3 months 
      }
    below is more correct

    Code:
      if (isset($_POST['remember'])) {
    	  $remember = $_SESSION["email"];
    	  setcookie("remember", $remember, time()+60*60*24*365);    //  3 months 
      }

  4. #4
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    The second one is better because the first one will sometimes -- if the error reporting level is high -- spit out errors.

  5. #5
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    where is error below during login[remember checkbox checked] ?
    Is it error set a php cookie, without unset first ?
    Or the session statement makes the error ?
    if FALSE THE (isset($_POST['remember'])) no error at all , well ?

    if (isset($_POST['remember'])) {
    $remember = $_SESSION["email"];
    setcookie("remember", $remember, time()+60*60*24*365); // 3 months // line 99
    }


    Warning: Cannot modify header information - headers already sent by (output started at /home/content/p/o/l/polisch123/html/customeradmin/processlogin.php:3) in /home/content/p/o/l/polisch123/html/customeradmin/processlogin.php on line 99

  6. #6
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    You cannot set a cookie after something has been sent to the user's browser.

    On a line somewhere before line 99, something has been output.

  7. #7
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    NEITHER unset a cookie, can I ?
    by using php and time prior today ?

    I use some javascript alerts prior...

  8. #8
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    No.

    You can't set or delete COOKIES after outputting something. Javascript is something.

  9. #9
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Below code appears this error, where the mistake ?

    Below code appears this error, where the mistake ?


    Warning: Cannot modify header information - headers already sent by (output started at /home/content/p/o/l/polisch123/html/dbinfo.php:18) in /home/content/p/o/l/polisch123/html/customeradmin/processlogin.php on line 37

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/p/o/l/polisch123/html/dbinfo.php:18) in /home/content/p/o/l/polisch123/html/customeradmin/processlogin.php on line 38


    setcookie("remember", $remember, time()+60*60*24*365); //line37
    setcookie("rememberp", $rememberp, time()+60*60*24*365); //line38

    Code:
    <?php session_start(); ?>
    <?php   
    include("../dbinfo.php");
    $linkid = mysql_connect($hostname,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");   // @
    
    $query ='';
    $query = "SELECT * FROM $CustomersTable WHERE status='active' AND email='".$_POST['email-login']."' AND password='".$_POST['password-login']."';";   
    
    $result = @mysql_query($query,$linkid);
    
    $count = @mysql_num_rows($result);
    
    
    if ($count > 0) { 
    
    		$row = mysql_fetch_assoc($result);
    		$_SESSION['title'] = $row['title'];
    		$_SESSION['name'] = $row['name'];
    		$_SESSION['license'] = $row['license'];
    		$_SESSION['passport'] = $row['passport'];
    		$_SESSION['address'] = $row['address'];
    		$_SESSION['city'] = $row['city'];
    		$_SESSION['state'] = $row['state'];
    		$_SESSION['postcode'] = $row['postcode'];
    		$_SESSION['country'] = $row['country'];
    		$_SESSION['mob'] = $row['mob'];
    		$_SESSION['fixed'] = $row['fixed'];
    		$_SESSION['password'] = $row['password'];		
      mysql_free_result($result);
      mysql_close($linkid); 
      $_SESSION["email"] = $_POST['email-login'];
      if (isset($_POST['remember'])) {
    	  
    	  $remember = $_SESSION["email"];
    	  $rememberp = $_SESSION["password"];
    	  setcookie("remember", $remember, time()+60*60*24*365);    
    	  setcookie("rememberp", $rememberp, time()+60*60*24*365);   
      } 
    }
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"><head><title>transfering.....</title></head><body><?php

  10. #10
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Your dbinfo.php has the problem.

    Delete the closing php tag from it ?> This is probably the problem.

    and be sure that there are no spaces before the opening <?php tag.

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
  •