Edited Field not changing when moving to next record(id).

First I would like to say I hope I will clearly explain my problem. OK, the problem I am having with the code is that when I edit a form is that the edited field doesn’t change along with rest of the fields when I move on to the next question. Saving works perfect fine and if I refresh the page the edited field (in this case the question) will go on to the next question.

Here’s some of jQuery (JavaScript) script that I think might be the culprit.
[php] function editRecord() {
$(’#editTrivia’)[0].reset(); // This kind of works, but still looks funky.
$id = id_array[x];
$.ajax({ // Start of ajax:
url: “getRecord.php?id=” + $id, // The PHP file that retrieves the questions:
dataType: “json”,
cache: true, // Format type:
success: function(info) { // Grab the data from php and then display it:
var confirmed = info.confirmed;
console.log(info);
id = info.trivia_id;
lastRec = info.lastRec;
question = info.trivia_question,
answer1 = info.answerA,
answer2 = info.answerB,
answer3 = info.answerC,
answer4 = info.answerD,
correct = info.correct;
$(’#editId’).attr(‘value’, id);

			recordNum(id);
			$question.text(question);
			$answerA.attr('value', answer1);
			$answerB.attr('value', answer2);
			$answerC.attr('value', answer3);
			$answerD.attr('value', answer4);
			
			removeSelected();
		  if (confirmed == 'yes') {
				$('#radio-1').prop('checked', true);
				$('#radio-1').addClass('onQuest');
				$('#radio-2').removeClass('offQuest');
				
			} 
			
			if (confirmed == 'no') {
				$('#radio-2').prop('checked', true);
				$('#radio-2').addClass('offQuest');
				$('#radio-1').removeClass('onQuest');
			}
															
			$('option.editOption').each(function() {
				if ( $(this).attr('value') == correct ) {
					$(this).prop('selected', 'selected');
				}
			});
			
		} // End of fetching data:
	}); // End of Ajax:
	
} // End of Display info:[/php] 

This is how I save the question:
[php] function saveEditData(myData) {
$.ajax({
type: ‘post’,
url: ‘saveEdit.php’,
data: myData,
success:function(info) {
displayEditTimer(5);
$(’#resultEdit’).html(info);
}
}); // End of Ajax Call:
}

$question.on('focusout', function() {				
	question = $(this).val();
	var params = { id: $id, question: $(this).val() };
	var myData = jQuery.param(params);
	console.log(myData);
	saveEditData(myData);
});[/php]

This is my HTML form:

[code]

Edit Trivia Question(s) Section



Add Question:

Possible Answer A:

Possible Answer B:

Possible Answer C:

Possible Answer D:

The Correct Answer is

Answer A
Answer B
Answer C
Answer D


Allow

Deny

  <input class="saveEditBtn" type="submit" name="submitEdit" value="Submit" tabindex="8">
</fieldset>
[/code]

and finally this is how I save my data in php:

[php]<?php
require(‘lib/includes/utilities.inc.php’);

if ( isset($_POST[‘id’])) {
$id = $_POST[‘id’];
$question = $_POST[‘question’];
try {
// Update the questions, answers and confirm:
$query = ‘UPDATE
movieTrivia
SET
question=:question,
dateAdded=NOW()
WHERE id=:id’;

	// Prepare the Statement:
	$stmt = $pdo->prepare($query);					

	// execute the statement:
	$result = $stmt->execute(array(':question' => $question,':id' => $id));
	
	if ($result) {
		echo 'Data Successfully Inserted';
	} else {
		echo 'Error.......';
	}		

} catch (Exception $e) { // Catch generic exceptions
}
}[/php]

Sorry for the long post, but explaining the problem without this amount of code would be really really confusing. Though it still might be, if it is be feel free to ask for more info.

I anyone can help, it will be greatly appreciated.

Best Regards,
John

P.S. I have used Google to find the answer to the problem, but to no avail that is why I’m asking it here.

I decided to add this to the comment as a reply. This how I retrieve the potential edited data using php:
[php]<?php
require(‘lib/includes/utilities.inc.php’);
if (isset($_GET[‘id’]) || !filter_var($_GET[‘direction’], FILTER_VALIDATE_INT, array(‘min_range’ => 1))) {

$id = $_GET[‘id’];
$e = array();

if (isset($current_id)) {

try {
  $query = "SELECT  id, confirm, question, answerA, answerB, answerC, answerD, correct FROM movieTrivia WHERE id=:id ORDER BY id ASC LIMIT 1";
  $stmt = $pdo->prepare($query);
  $result = $stmt->execute(array(':id' => $id));

// If the query ran OK, fetch the record into an object:
  if ($result) {

    $stmt->setFetchMode(PDO::FETCH_CLASS, 'MovieTriviaData');
    $trivia = $stmt->fetch();
   
    	$e['trivia_id'] = $trivia->getId(); 
				$e['confirmed'] = $trivia->getConfirm();
    	$e['trivia_question'] = $trivia->getQuestion();
    	$e['answerA'] = $trivia->getAnswerA();
    	$e['answerB'] = $trivia->getAnswerB();
    	$e['answerC'] = $trivia->getAnswerC();
    	$e['answerD'] = $trivia->getAnswerD();
				$e['correct'] = $trivia->getCorrect();

  } else {
    throw new Exception('An invalid page ID was provided to this page');
  }
} catch (Exception $e) { // Catch generic exceptions
 
}

}

print json_encode($e);

}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service