Hello, Im creating a quiz creator in html and php. I have a simple form where the user inputs data. when it gets to the answer part thats where im getting messed up. i have 3 input boxes, 1 for answer 1, one for answer 2, and one for answer three. how can i have it talk to the php to know which one is the correct answer? would i need to put a check box next to each field to check off the correct one? if so how would i create my if statement. i need it like this (im formatting it in xml) so if the user placed text in the correct answer box, it would display like below <answer correct="y">Blue</answer> otherwise it would look like <answer>blue</answer> thanks for the help.
Do you want the checking to be done in real time as the data is put in, or do you want it checked when the user submits the form?
I don't know anything about xml, but as you need help in php, you can do that with if statements and $_POST: <?php if ($_POST['answer1']=='correctvalue'){ //correct answer }else{ //uncorrect answer } ?> PHP: As I said, I know nothing about XML, but if you are only formatting it (inside a .php page), you can do it this way: <?php if ($_POST['answer1']=='correctvalue'){ $add=' correct="y"'; }else{ $add=""; } echo '<answer'.$add.'>'.$_POST['answer1'].'</answer'>; ?> PHP: What it does: if it is correct it adds correct=y to the answer tag, otherwise it doesn't. hope that helps
three check box names are equal but values are different you can click only one check at a time you get value from that name
those are radio buttons, not checkboxes <input type=radio name=quiz value=Answer1>Answer1<br> <input type=radio name=quiz value=Answer2>Answer2<br> <input type=radio name=quiz value=Answer3>Answer3
Im getting there! ok heres whats happening: i have 3 radio buttons in the same group: <input name="correct" type="radio" id="radio" value="correctAnswer1"> <input name="correct" type="radio" id="radio" value="correctAnswer2"> <input name="correct" type="radio" id="radio" value="correctAnswer3"> with php code: $correct = $_POST['correct']; if ($_POST['correct'] == 'correctAnswer1') { //Correct Answer $add =' correct="y"'; }else{ //Wrong Answer $add=""; } my echo is: echo ("<" . "answer" . $add . ">" . "<" . "![CDATA[" . $txtAnswer1 . "]]>" . "<" . "/" . "answer" . ">"); and my output is: <answer correct="y"><![CDATA[Blue]]></answer> <answer correct="y"><![CDATA[Red]]></answer> <answer correct="y"><![CDATA[Green]]></answer> so when i fill in 1 radio button on the form,..they are all getting a value of "correct=y" and not just the specific one clicked... any help would be greatly appreciated!! Thanks, -Tim
ok i figured it out, i duplicated the if statement 3 times, 1 for each answer, and now it works appropriately, thanks!