Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The params should be comma separated, but you don't really need params when taking from superglobal array. However, you only need to call the function if <code>'yes'</code> for example:</p> <pre><code>&lt;form action="choice.php" method="post"&gt; &lt;input type="submit" name="choice" value="yes" /&gt; &lt;input type="submit" name="choice" value="no" /&gt; &lt;!-- You'd better use radio buttons --&gt; &lt;/form&gt; &lt;?php function choice() { if ($db-&gt;query("UPDATE ..... ;")) { return true; } return false; } if (isset($_POST['choice']) &amp;&amp; $_POST['choice'] == 'yes') { choice(); } else { echo 'no'; } ?&gt; </code></pre> <hr> <p>Ofcourse you can have multiple if's, but I don't think it will help you enough:</p> <pre><code>if (isset($_POST['choice']) &amp;&amp; $_POST['choice'] == 'yes') { //something; } elseif (isset($_POST['choice']) &amp;&amp; $_POST['choice'] == 'no') { //something else; } elseif (isset($_POST['choice']) &amp;&amp; $_POST['choice'] == 'maybe') { //something else; } </code></pre> <p>If you want the function to update db with the value from the user, you could use something like this:</p> <pre><code>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-&gt;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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload