Note that there are some explanatory texts on larger screens.

plurals
  1. POImmediately update database on click of radio
    text
    copied!<p>I have several forms with radio buttons on a page. My goal is to have the database updated immediately on the click of a radio button. Here is what I have put together so far, but I'm not sure where to go from here.</p> <pre><code>&lt;? include 'dbconnect.inc.php';?&gt; &lt;script type="text/javascript"&gt;function do_submit(){document.forms['decision'].submit();}&lt;/script&gt; &lt;? $result = $mysqli-&gt;query("SELECT * FROM items"); while( $row = $result-&gt;fetch_assoc() ){ ?&gt; &lt;form name='decision' method='post' action='action.php'&gt; &lt;label&gt;Keep:&lt;/label&gt;&lt;input type='radio' name='dec' value='keep' onchange='do_submit()' &lt;? if($row['Dec1']=='keep'){echo "checked='checked'";} ?&gt; &gt; &lt;label&gt;Donate:&lt;/label&gt;&lt;input type='radio' name='dec' value='donate' onchange='do_submit()' &lt;? if($row['Dec1']=='donate'){echo "checked='checked'";} ?&gt; &gt; &lt;label&gt;Sell:&lt;/label&gt;&lt;input type='radio' name='dec' value='sell' onchange='do_submit()' &lt;? if($row['Dec1']=='sell'){echo "checked='checked'";} ?&gt; &gt; &lt;label&gt;Trash:&lt;/label&gt;&lt;input type='radio' name='dec' value='trash' onchange='do_submit()' &lt;? if($row['Dec1']=='trash'){echo "checked='checked'";} ?&gt; &gt; &lt;label&gt;Give To:&lt;/label&gt;&lt;input type='text' name='dec' size='15' onchange='do_submit()' &lt;? if($row['Dec1']!='keep' || $row['Dec1']!='donate' || $row['Dec1']!='sell' || $row['Dec1']!='trash'){echo $row['Dec1'];} ?&gt; &gt; &lt;input type='hidden' name='Id' value='&lt;? echo $row['Id']; ?&gt;' /&gt; &lt;/form&gt; &lt;? } ?&gt; </code></pre> <p>action.php</p> <pre><code>&lt;? $mysqli-&gt;query("UPDATE items SET Dec1 = '{$_POST['dec']}' WHERE Id = '{$_POST['$Id']}'") or die(mysqli_error($mysqli)); ?&gt; </code></pre> <p>Am I anywhere close? Can someone help me through this?</p>
 

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