Why does this code not work:
PHP Code:{
$checked=$_POST['checked'];
$cookie_val=1
if(isset($checked=='checked'))){
set_cookie('BSComputers', $cookie_val, time()+(3600*24*365));
} else {
};
Printable View
Why does this code not work:
PHP Code:{
$checked=$_POST['checked'];
$cookie_val=1
if(isset($checked=='checked'))){
set_cookie('BSComputers', $cookie_val, time()+(3600*24*365));
} else {
};
The objects 'checked' is a checkbox
isset() can only be used with variables, it makes no sense with an expression as you have used.
The snippet can be rewritten simply as
PHP Code:if (isset($_POST['checked']) && (bool)$_POST['checked']) {
set_cookie('BSComputers', 1, time() + 3600 * 24 * 365);
}
It doesn't really works...I don't understand what that (bool) is there for? How should the checkbox be named with this code?
I assumed the checkbox was named "checked".
(bool) is to convert the checkbox value into a boolean. It's not really necessary.