Alesfatalis
Alesfatalis

Reputation: 777

if checkbox is checked set status to OK

Hey guy i have following problem: I have this line of code which includes a checkbox:

echo('<td bgcolor="'.$Color.'"><input type="checkbox" name="altgeraet" value="'.$resultarray['Status_Altgeraet'].'"></td');

Now i want when the checkbox is selected the mysql value of Status_Altgeraet is set to OK if not it should be set to NOK. At the bottom of my page there is a button when then someone klicks it it goes to my next php file where all data is processed. Here is the point where the mysql value shoul be updated. I have tried following to get the checkbox in to an variable to work with it but it seems not to work:

$Altgeraet = $REQUEST['Status_Altgeraet']));

I am no php expert just an beginner. Hope you guys can give me some tips to solve it :)

Upvotes: 0

Views: 116

Answers (1)

Dan Grossman
Dan Grossman

Reputation: 52372

$Altgeraet = isset($REQUEST['altgeraet']) ? 'OK' : 'NOK';

Or in a more familiar syntax:

if (isset($_REQUEST['altgeraet'])) {
    $Altgeraet = 'OK';
} else {
    $Altgeraet = 'NOK';
}

If the checkbox is not checked, it will not be present in $_REQUEST/$_GET/$_POST at all.

Upvotes: 4

Related Questions