form php mysql
hi! I'm making this tests in php with questions I've got in a MySql db and trying to get the form to retrieve the answers from users. The problem I have is that the 'submit' and 'reset' buttons are placed for each question, or they appear one time but It doesn't allow you to choose the answers for all questions, as it understands it all multiple choice question belong to the same form since they have the same 'name'.
I appreciate any suggestions, here is the code:
<html><head><title>TEST</title></head>
<body><form action='<?php print $PHP_SELF;?>' method='post'>
<?php
// Conectamos con el servidor
$con = mysql_connect('localhost', '', '') OR die('No he podido conectar con el servidor');
// Selección de la base de datos donde está nuestras tablas
mysql_select_db('examenes') OR die('No pude seleccionar la base de datos');
// Definimos la consulta SQL dentro de una variable
$sql = "SELECT * FROM preguntas WHERE Num_Examen = 0";
// Ejecutamos la consulta y el resultado lo guardamos en $result
$result = mysql_query($sql) OR die('La consulta SQL no se ha podido realizar');
// Si la consulta se ha realizado, pero no ha devuelto ninguna tupla
if (0 == mysql_num_rows($result)){
// Decimos que no hay preguntas
print "No hay preguntas definidas para el examen 0";
// Si ha devuelto alguna tupla
} else {
// Las vamos leyendo una a una, asignandolas a la variable $tupla
While ($Pregunta = mysql_fetch_assoc($result)){
// Imprime numero de Pregunta
print "Pregunta Nº ";
print $Pregunta[Num_Pregunta];
print "<br/>\n";
// Imprime la pregunta en si
print $Pregunta[Pregunta]."<br/>\n";
// Si hay definida una imágen la muestra
if (0 < strlen($Pregunta[Imagen])){
print "<img src='$Pregunta[Imagen]'><br/>";
}
// Imprime las respuestas posibles
//print "<pre>\n";
//print_r($Pregunta);
// print"</pre>\n";
print "Respuestas : <br/>\n";
print "A - $Pregunta[Resp_1] <input type='radio' name='r'><br/>\n";
print "B - $Pregunta[Resp_2] <input type='radio' name='r'><br/>\n";
print "C - $Pregunta[Resp_3] <input type='radio' name='r'><br/>\n";
print "D - $Pregunta[Resp_4] <input type='radio' name='r'><br/>\n";
print "\n";
}
}
?><input type='submit' value='Enviar'></form></body>
</html>
|