mardi 24 mai 2016

How to retrieve the values of radio button in MYSQL?

I have a html table, each row have a radio button that generate dynamically. In the database table, I set the value of the radio button as "No" and now, I want to retrieve this value from MYSQl and displayed it to radio button html tag.

Then if the user choose "Yes" option in the radio button html tag, there's a confirmation box with "Ok" and "Cancel" buttons, if the user click Ok the value of the radio button in the database table with the same row will update.

But my snippets are not working. The database table is not updating. How to fix this?

<?php
    if (isset($_POST['list_location']) && $_POST['list_location'] != 'Select by Location'){
        $list_position= $_POST['list_location'];
        $result_position= $wpdb->get_results($wpdb->prepare("SELECT submit_time, last_name, first_name, middle_name, mobile_number, email, location, position, message, attachment_resume_id FROM resume_databank WHERE process_resume= '" . $list_processed . "' ORDER BY location ASC", OBJECT));

        echo '<table id="paginate_result">';
        echo '<tr>';
        $optionId = 0;
        echo '<th>Submit Time</th>';
        echo '<th>Last Name</th>';
        echo '<th>First Name</th>';
        echo '<th>Middle Name</th>';
        echo '<th>Mobile Number</th>';
        echo '<th>Email</th>';
        echo '<th>Location</th>';
        echo '<th>Position</th>';
        echo '<th>Message</th>';
        echo '<th>Resume</th>';
        echo '<th>Processed?</th>';

        foreach ($result_position as $record_s){
            $optionId++;
            //$optionId = $record_s['id'];
            echo '<tr>';
            echo '<td id="submit_time">' . $record_s->submit_time . '</td>';
            echo '<td id="last_name">' . $record_s->last_name . '</td>';
            echo '<td id="first_name">' . $record_s->first_name . '</td>';
            echo '<td id="middle_name">' . $record_s->middle_name . '</td>';
            echo '<td id="mobile_number">' . preg_replace("/([0-9]{3})([0-9]{4})([0-9]{4})/", "($1) $2-$3", $record_s->mobile_number) . '</td>';
            echo '<td id="email">' . $record_s->email . '</td>';
            echo '<td id="location">' . $record_s->location . '</td>';
            echo '<td id="position">' . $record_s->position . '</td>';
            echo '<td id="message">' . $record_s->message . '</td>';
            echo '<td id="resumeFile'.$optionId.'">' . $record_s->attachment_resume_id . '</td>';
            echo '<td id="processedYes><label for="Yes">Yes</label>
            <input type="radio" id="processedOptionYes'.$optionId.'" name="processedOption" value="Yes" onclick="proccessedCheck('.$optionId.',\'Yes\')"/>
            <label for="No">No</label>
            <input type="radio" id="processedOptionNo'.$optionId.'" name="processedOption" value="No" checked="checked" onclick="proccessedCheck('.$optionId.',\'No\')" echo $record_s->process_resume === "No" checked="checked"/>/>No</td>';
            echo '</tr>';
        }

        echo '</table>';
    }

    $optionAnswer = '';

    if (isset($_POST['optionAnswer']) == 'Yes'){
        $optionAnswer = $_POST['optionAnswer'];
        $queryOption = $wpdb->query($wpdb->prepare("UPDATE resume_databank SET process_resume='$optionAnswer' WHERE id = %d", $id->ID));
    }
?>

Hidden Form:

<form id='hiddenForm' method='POST' action=''>
    <input type="hidden" id="inputHidden1" name="optionId" />
    <input type="hidden" id="inputHidden2" name="optionAnswer" />
</form>

JS:

function proccessedCheck(optionId,optionAnswer){
    if(optionAnswer == 'Yes'){
        if (confirm('You have chosen ' + optionAnswer + ', is this correct?')){
            jQuery("#processedOptionYes" + optionId).attr('disabled',true);
            jQuery("#processedOptionNo" + optionId).attr('disabled',true);
            var withlink = jQuery("#resumeFile"+ optionId).html();
            var withoutlink = jQuery(withlink).html();
            jQuery("#resumeFile"+optionId).html("").append(withoutlink);
            jQuery("#inputHidden1").val(optionId);
            jQuery("#inputHidden2").val(optionAnswer);
            jQuery("#hiddenForm").submit();
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire