Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect menu not being updated with new information that has been added
    primarykey
    data
    text
    <p>Initially when the page loads, ajax populates a selectmenu. When I enter new patient information it is added to the database but the patient selectmenu does not get append to/refresh with that new patient being selected.</p> <p>I was hoping someone could help me with what Im doing wrong.</p> <p>Ajax call</p> <pre><code>$('#newpatient').click(function() { var patientadd = $('#patientaddform').serializeArray(); $.ajax({ url: 'patientadd.php', type: "POST", data: patientadd, dataType: 'json', success: function(data) { var html = ''; var len = data.length; for (var i = 0; i &lt; len; i++) { html += '&lt;option value="' + data[i].patient_id + '"&gt;' + data[i].patient_firstname + ' ' + data[i].patient_lastname + '&lt;/option&gt;'; } $('#patientselect').append(html); }, complete: function() { $('#patientselect').selectmenu('refresh', true); } }); });​ </code></pre> <p>patientadd.php</p> <pre><code>if (empty($_POST) === false) { $update_data = array('company_id' = &gt; $_POST['company_id'], 'addpatient_firstname' = &gt; $_POST['addpatient_firstname'], 'addpatient_lastname' = &gt; $_POST['addpatient_lastname'], 'addpatient_dob' = &gt; $_POST['addpatient_dob'], 'patient_added' = &gt; $_POST['patient_added']); $required_fields = array('company_id', 'addpatient_firstname', 'addpatient_lastname', 'addpatient_dob', 'patient_added'); foreach($update_data as $key = &gt; $value) { if (empty($value) &amp;&amp; in_array($key, $required_fields) === true) { $errors[] = 'Fields marked with an asterisk are required'; break 1; } } } if (empty($_POST) === false &amp;&amp; empty($errors) === true) { $company_id = $_POST['company_id']; $patient_id = $_POST['addpatient_id']; $first_name = $_POST['addpatient_firstname']; $last_name = $_POST['addpatient_lastname']; $dob = $_POST['addpatient_dob']; $updated = $_POST['patient_added']; $update = array(); array_walk($update_data, 'array_sanitize'); foreach($update_data as $field = &gt; $data) { $update[] = '`'.$field.'` = \''.$data.'\''; } mysql_query("INSERT INTO `lab`.`patients` (`company_id`, `patient_id`, `patient_firstname`, `patient_lastname`, `patient_dob`, `patient_added`) VALUES ('$company_id', NULL, '$first_name', '$last_name', '$dob', '$updated')"); $patient_id = mysql_insert_id(); /*echo '&lt;strong&gt;' . $patient_id . ' ' . $first_name . ' ' . $last_name . '&lt;/strong&gt; has been added!';*/ } $data = array('patient_id' = &gt; $patient_id, 'patient_firstname' = &gt; $first_name, 'patient_lastname' = &gt; $last_name); echo json_encode($data); </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. This table or related slice is empty.
    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