I have no idea why this won't work. It is wrapped up in a wordpress plugin that I am working on. All of the other stuff works (text area for the question, etc) but the answer value and answer content won't go into the database. In fact, it deletes the answer completely out of the database. If I prefill the data into the database, it displays it into the fields correctly. If I click save it reloads the page with no answers. I've been at this for a few hours now and I am goin crazy. Anyone got an idea of what I am doing wrong here?


$action = 'new';
if($_REQUEST['action'] == 'edit') $action = 'edit';

$question= $wpdb->get_row($wpdb->prepare("SELECT question, explanation FROM {$wpdb->prefix}quiz_question WHERE ID=%d", $_REQUEST['question']));
$all_answers = $wpdb->get_results($wpdb->prepare("SELECT answer,answer_value FROM {$wpdb->prefix}quiz_answer WHERE question_id=%d ORDER BY sort_order", $_REQUEST['question']));

$answer_count = 2;
if($action == 'edit' and $answer_count < count($all_answers)) $answer_count = count($all_answers) ;

<div class="wrap">
	<script type="text/javascript">
		var answer_count = <?php echo $answer_count?>;

		function newAnswer() {
			var para = document.createElement("p");
			var textarea = document.createElement("textarea");
			textarea.setAttribute("name", "answer[]");
			textarea.setAttribute("rows", "3");
			textarea.setAttribute("cols", "50");
			var input = document.createElement("input");
			input.setAttribute("type", "text");
			input.setAttribute("name", "answer_value[]");
			input.className = "answer_value";
			input.setAttribute("value", answer_count);
			input.setAttribute("id", "answer_value_" + answer_count);
			//$("extra-answers").innerHTML += code.replace(/%%NUMBER%%/g, answer_count);
		function init() {
			jQuery("#post").submit(function(e) {
				// We must have at least 2 answers.
				var answer_count = 0
				jQuery(".answer").each(function() {
					if(this.value) answer_count++;
				if(answer_count < 2) {
					alert("<?php e("Please enter at least two answers"); ?>");
					return true;

				var valid_answer = false;
				// Make sure at least one answer has a value more than 0.
				for (i=0;i<answer_count;i++){
					if (answer_value > 0){
						valid_answer = true;
				if(!valid_answer) {
					alert("<?php e("Please enter more than 0 points to one answer."); ?>");
	<form name="post" action="edit.php?page=quizzin/question.php&amp;quiz=<?php echo $_REQUEST['quiz']; ?>" method="post" id="post">
	<div id="poststuff">
		<div class="postbox">
			<h3 class="hndle"><span><?php e('Answers') ?></span></h3>
			<div class="inside">			
				<?php for($i=1; $i<=$answer_count; $i++) { ?>
					<p><textarea name="answer[]" class="answer" rows="3" cols="50"><?php if($action == 'edit') echo stripslashes($all_answers[$i-1]->answer); ?></textarea>
					<input name="answer_value[]" class="answer_value" type="text" size="2" value="<?php echo stripslashes($all_answers[$i-1]->answer_value); ?>" /></p>
				<?php } ?>
				<div id="extra-answers"></div>
					<a href="javascript:newAnswer();"><?php e("Add New Answer"); ?></a>
		<p class="submit">
			<input type="submit" name="submit" value="<?php e('Save') ?>" style="font-weight: bold;" />