Я новичок в PHP, прошу сильно не пинать, пишу тест, такая ситуация что при отправки данных с формы вопрос повторяется 2 раза, не могу понять что за фигня :-(
<?php session_start();
$login=$_SESSION['name_id']; //принимаем логин
$max_row_user=$_SESSION['perem']; //принимаем переменную
$max_ver=$_SESSION['vers'];
require "mysql.php";
mysql_query("set names utf8");
$podr_user="select id_test from 1c_users where Fio='$login' LIMIT 1"; //ищем id_test
$id_user="select id_1cuser from 1c_users where Fio='$login' LIMIT 1"; //ищем id_пользователя
$user=mysql_query($id_user) or die ('Error $id_user' . mysql_error());
$no_fantazy=mysql_fetch_row($user);
$id=$no_fantazy[0]; //выбираем id
$podr_query=mysql_query($podr_user) or die('Error query podr' . mysql_error());
$podr=mysql_fetch_row($podr_query);
if ($podr[0]==1) {$nametest="для работников Аппарата Управления"; $id_test=1;} elseif ($podr[0]==4) {$nametest="для работников Механического завода";$id_test=4;} elseif ($podr[0]==2) {$nametest="для работников ЗМИК";$id_test=2;} elseif ($podr[0]==3) {$nametest="для работников ТИСМА"; $id_test=3;}
$_SESSION['nametest']=$nametest;
$max_kol_query=mysql_query("select count(*) from journal where id_user=$id") or die(mysql_error());
$max_kol=mysql_fetch_row($max_kol_query);
$quest_user="select vopros,id_vopros from vopros where id_test=$id_test and id_vopros not in (select id_vopros from journal where id_user=$id and id_test=$id_test and version=$max_ver) LIMIT 1";
if ($max_kol[0]<=$max_row_user )
{
$quest_query=mysql_query($quest_user) or die('Error query podr' . mysql_error());
while ($row = mysql_fetch_row($quest_query,MYSQL_ASSOC)) {
$array_vopros_id[]=$row['id_vopros'];
$array_vopros[]=$row['vopros'];
}
srand ((float) microtime() * 10000000);
$input = $array_vopros_id;
$rand_keys = array_rand($input);
$id_vopros=$input[$rand_keys];
$query_vopros=$array_vopros[$rand_keys];
$quest_random=array_rand($array_vopros_id);
$query_report=mysql_query("select otvet from otvet inner join vopros on otvet.id_vopros=vopros.id_vopros where vopros.id_vopros=$id_vopros") or die('Error query report' . mysql_error());
//в отбор массива исключить уже имеющийся id_vopros
while ($row = mysql_fetch_assoc($query_report) ) {
$report[] = $row['otvet'];
}
$otvet_query="select id_otvet from otvet inner join vopros on otvet.id_vopros=vopros.id_vopros where vopros.id_vopros=$id_vopros"; //выбираем ответы соответствующие вопросам
$otvet_exec=mysql_query($otvet_query) or die('Error query true fatal' . mysql_error());
while ($orow = mysql_fetch_assoc($otvet_exec) ) {
$otvet[] = $orow['id_otvet'];
}
@$cont_otvet1="select otvet from otvet where id_otvet=$otvet[0]";
@$cont_otvet2="select otvet from otvet where id_otvet=$otvet[1]";
@$cont_otvet3="select otvet from otvet where id_otvet=$otvet[2]";
$cont_otvet1_exec=mysql_query($cont_otvet1) or die('Error query true fatal' . mysql_error());
$cont_otvet2_exec=mysql_query($cont_otvet2) or die('Error query true fatal' . mysql_error());
$cont_otvet3_exec=mysql_query($cont_otvet3) or die('Error query true fatal' . mysql_error());
$cont1=mysql_fetch_row($cont_otvet1_exec);
$cont2=mysql_fetch_row($cont_otvet2_exec);
$cont3=mysql_fetch_row($cont_otvet3_exec);
$radio=$_POST['radio'];
$Sub=$_POST['Sub'];
if (!isset($radio)) {
$radio=0;
}
$vopr_query="select id_vopros from otvet where id_otvet=$radio";
$vopr_exec=mysql_query($vopr_query);
$vopr=mysql_fetch_row($vopr_exec);
$vopros=$vopr[0];
if (!isset($vopros)) {
$vopros=0;
}
if (isset($Sub)) {
$query="insert into journal(id_otvet,id_user,id_vopros,id_test,version) values ($radio,$id,$vopros,$id_test,$max_ver)";
$query_exec=mysql_query($query) or die ('Error query_exec' . mysql_error());
echo "otvet_query - $otvet_query <br />"; echo "otvet - $otvet <br />"; echo "vopros - $vopros<br />"; echo "$podr_user <br />"; echo "id_user - $id_user<br />"; echo "user - $user<br />"; echo "quest_user - $quest_user<br />";
}
}
else
{
Header("Location: http://172.24.118.219/seans/statistic.php");
//Header("Location: http://127.0.0.1/seans/statistic.php");
echo "<hr>";
echo "Тест закончен";
echo "<hr>";
exit;
}
echo '
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Тест</title>
<meta name="generator" content="Amaya, see http://www.w3.org/Amaya/" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
</head>
<body>
<script language=javascript>
var intLeft = 180; // Время в секундах
function GoPage() {
if (0 == intLeft)
//location.replace("testing.php")
document.test.Sub.click()
else {
intLeft -= 1;
document.getElementById( "gotopage" ).innerHTML = intLeft + " ";
setTimeout("GoPage()", 1000);
}
}
</script>
</head>
<body onload="setTimeout(\'GoPage()\', 1000)">
<div class=promo align=center><br><br>
</div>
<br><br>
<center>
<h2>Время на вопрос:
<b id=gotopage>
<script language=javascript>
document.write(intLeft);
</script>
</b>
</h2>';
echo "
<form name=test method=POST action=testing.php>
<p align=center><table border=1 width=600 bgcolor=#ffcc00>
<col />
<tbody>
<tr>
<td><h1 style=text-align:center;margin-left:auto;margin-right:auto;>Тест </h1><p align=center>$nametest</p></td>
</tr>
<tr>
<td><h3
style=text-align:center;margin-left:auto;margin-right:auto;>Тестируемый
</h3><p align=center><i>$login</i></p></td>
</tr>
<tr>
<td><p align=center> $query_vopros </font></p><br><p align=center>$image</p></td>
</tr>
<tr>
<td><p align=center><font FACE= Arial Black, Courier, Times New Romain, Courier New COLOR=black><input type=radio name=radio value=$otvet[0] />$cont1[0] </font></p></td>
</tr>
<tr>
<td><p align=center><font FACE= Arial Black, Courier, Times New Romain, Courier New COLOR=black><input type=radio name=radio value=$otvet[1] />$cont2[0]</font></td>
</tr>
<tr>
<td><p align=center><font FACE= Arial Black, Courier, Times New Romain, Courier New COLOR=black><input type=radio name=radio value=$otvet[2] />$cont3[0]</font></td>
</tr>
<tr>
<td><p align=center>
<input name=Sub type=submit value=OK></p></td>
</tbody>
</table></p>
</form>
</body>
</html>
";
?>