PDA

View Full Version : checkboxes and php



leonidassavvides
03-05-2009, 10:35 AM
if in a form we have
<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 ?

techietim
03-05-2009, 10:54 AM
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:


$has_checkbox_been_checked = isset($_POST['remember']); //returns a boolean

leonidassavvides
03-05-2009, 11:18 AM
is it wrong the

remember=checkbox

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

below is more correct


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

techietim
03-05-2009, 11:44 AM
The second one is better because the first one will sometimes -- if the error reporting level is high -- spit out errors.

leonidassavvides
03-07-2009, 10:37 AM
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

JasonDFR
03-07-2009, 10:41 AM
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.

leonidassavvides
03-08-2009, 08:28 PM
NEITHER unset a cookie, can I ?
by using php and time prior today ?

I use some javascript alerts prior...

JasonDFR
03-09-2009, 06:36 AM
No.

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

leonidassavvides
03-09-2009, 03:21 PM
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


<?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

JasonDFR
03-09-2009, 03:41 PM
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.