パラメータはコンマで区切る必要がありますが、スーパーグローバル配列から取得する場合、実際にはパラメータは必要ありません。'yes'
ただし、関数を呼び出す必要があるのは、たとえば次の場合のみです。
<form action="choice.php" method="post">
<input type="submit" name="choice" value="yes" />
<input type="submit" name="choice" value="no" /> <!-- You'd better use radio buttons -->
</form>
<?php
function choice() {
if ($db->query("UPDATE ..... ;")) {
return true;
}
return false;
}
if (isset($_POST['choice']) && $_POST['choice'] == 'yes') {
choice();
}
else {
echo 'no';
}
?>
もちろん、複数の if を使用できますが、十分に役立つとは思いません。
if (isset($_POST['choice']) && $_POST['choice'] == 'yes') {
//something;
}
elseif (isset($_POST['choice']) && $_POST['choice'] == 'no') {
//something else;
}
elseif (isset($_POST['choice']) && $_POST['choice'] == 'maybe') {
//something else;
}
関数でユーザーからの値で db を更新する場合は、次のようなものを使用できます。
function choice() {
$choices = array('yes', 'no', 'maybe', 'dunno'); //predefined choices
if (in_array($_POST['choice'], $choices)) { //checks if the user input is one of the predefined choices (yes, no, maybe or dunno)
if($db->query("UPDATE table1 SET userchoice = '{$_POST['choice']}' WHERE user_id = '{$_SESSION['id']}';")) {
return true;
}
}
return false;
}
if (isset($_POST['choice'])) choice(); //so here you don't need (not necessary, but you can) to check if the value is the one you want. If it's set, you call choice(), then the function checks if it's in the array of predefined choices, so if it is - it will update, if it's not it will return false