Note that there are some explanatory texts on larger screens.

plurals
  1. POAutosave from php to mysql without page change or submit button
    text
    copied!<p>Basically I have a list of data that is shown via a foreach statement from a table in my database. I want a dropdown list next to each that has some values in them that need to be saved to a field in my table, however I want to autosave the value in the dropdown list to the field as soon as the value in it is changed. Can anyone point me to a tutorial or something that might help?</p> <p>I am using php and mysql to create the system, but will happily use JavaScript if required</p> <p>I have had a look at this: <a href="http://www.dynamicdrive.com/dynamicindex16/autosaveform.htm" rel="nofollow noreferrer">dynamic Drive Autosave</a><a href="http://www.dynamicdrive.com/dynamicindex16/autosaveform.htm" rel="nofollow noreferrer">http://www.dynamicdrive.com/dynamicindex16/autosaveform.htm</a> which is similar to what i want, however i need it to actually store that data in my database not temporary storage.</p> <p>Any Guidance appreciated,</p> <p>Ian</p> <hr> <p><strong>BIG EDIT</strong></p> <p>So, thankyou for the replys but I have no clue about ajax call.....I found this:<a href="https://stackoverflow.com/questions/7682713/how-to-auto-save-selection-in-combobox-into-mysql-in-php-without-submit-button">How to Auto Save Selection in ComboBox into MYSQL in PHP without submit button?</a>.</p> <p>can i get it to work?</p> <pre><code>&lt;script&gt; $(document).ready(function(){ $('select').live('change',function () { var statusVal = $(this).val(); alert(statusVal); $.ajax({ type: "POST", url: "saveStatus.php", data: {statusType : statusVal }, success: function(msg) { $('#autosavenotify').text(msg); } }) }); }); &lt;/script&gt; &lt;?php foreach ( $results['jobs'] as $job ) { ?&gt; &lt;td width="25%"&gt;&lt;?php echo $job-&gt;job_id&lt;/td&gt; &lt;td&gt; &lt;select name="status" id="status"&gt; &lt;option value=''&gt;--Select--&lt;/option&gt; &lt;option value='0'&gt;Approve&lt;/option&gt; &lt;option value='1'&gt;Reject&lt;/option&gt; &lt;option value='2'&gt;Pending&lt;/option&gt; &lt;/select&gt; &lt;div id="autosavenotify"&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; </code></pre> <p>and on the page saveStatus.php:</p> <pre><code>&lt;?php if (isset($_POST['statusType'])) { $con=mysql_connect("localhost","username","mypass","rocketdb3"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("jobs", $con); $st=$_POST['statusType']; $query = "UPDATE jobs SET status=$st WHERE job_id=$id"; $resource = mysql_query($query) or die (mysql_error()); } ?&gt; </code></pre>
 

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