Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I have created an exercise on which one column has words and the second column has the pronounce.

The second column is shuffled.

The code which shows the results is:
while($row = pg_fetch_array($ideo_results)){
	$pinyin_query = "select id, pinnin from temp_match where ideogram = '".$row['ideogram']."'";
	$pinyin_results = pg_query($cn, $pinyin_query);
	while($line = pg_fetch_array($pinyin_results)){
		echo "<tr>
		<td><input id='getIdeo' type=radio name='ideogram' value='".$row['ideogram']."'>".$row['ideogram']."</td>
		<td><input id='getPin' type=radio name='pinnin' value='".$line['pinnin']."'>".$line['pinnin']."</td><td><div id=results></div></td>";
	}
}



I change the code and I made them as radio buttons.
I use jquery to post it on another PHP page for check BUT I cannot get the values from the selected radio buttons, but only the 2 first values.

What I have tried:

function quiz() {
    var getIdeo = $("#getIdeo").checked.val();
    var getPin = $("#getPin").checked.val();
    $.post("match_check.php", { getIdeo: getIdeo, getPin: getPin },
    function(data) {
	 $('#results').html(data);
	 $('#myForm')[0].reset();
    });
}


<input type='button' id='check_quiz' onclick='quiz()' value='Check'>
Posted
Updated 30-Apr-22 11:01am
v2
Comments
Richard Deeming 3-May-22 12:32pm    
Your code is potentially vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.
PHP: SQL Injection - Manual[^]
PHP: Prepared statements and stored procedures - Manual[^]

1 solution

I had to change two lines:

var getIdeo = $('input[name="ideogram"]:checked').val();
    var getPin = $('input[name="pinnin"]:checked').val();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900