php - 无法调试随机错误

标签 php mysql

我有一个基于网络的自定义门票销售,是我为 friend 制作的,每当我尝试(在任何浏览器上)时,它都运行良好。然而,当它昨天上线时,一些人试图订票,他们会收到他们的电子邮件,说他们已经预订了座位(一切正常),但系统只会记录其中的一些座位。

假设如果他们预订了 A1 - A10,他们会收到一封电子邮件,说他们预订了这些,但系统只会预订 A1 - A5(或 A6 左右,这似乎是随机的)。

此外,这不会发生在每个人身上,它只是随机发生(至少我还没有找到它发生的适当原因)。

我订票的时候密码在这里:

$cantTotal=0;

$boletosF1 = $_POST['funcion1Hidden'];
if($boletosF1!=""){
$lugares = explode(" ", $boletosF1);
$cant = count($lugares);
$cantTotal += $cant;

$f1 = "";
$sqlAP = "SELECT * FROM apartados";
if ($resultAP = mysql_query($sqlAP)) {
    while ($rowAP = mysql_fetch_array($resultApP)) {
        $f = $rowAP['funcion'];
        $lugar = $rowAP['lugar'];
        $count++;
        if ($f == "F1") {
            $f1.= ( $lugar . " ");
        }
    }
}
$sqlPag2 = "SELECT * FROM pagados";
if ($resultPag2 = mysql_query($sqlPag2)) {
    while ($rowPag2 = mysql_fetch_array($resultPag2)) {
        $f = $rowPag2['funcion'];
        $lugar = $rowPag2['lugar'];
        $count++;
        if ($f == "F1") {
            $f1.= ( $lugar . " ");
        }
    }
}
$func = explode(" ", $f1);
$cantUtilizados = count($func);
$repetidos = 0;
for ($int = 0; $int < $cant; $int++) {
    for ($r = 0; $r < $cantUtilizados; $r++) {
        if ($func[$r] == $lugares[$int]) {
            $repetidos++;
        }
    }
}
if ($repetidos > 0) {
    redirect("apartadoBoletos.php?error=1");
}
}
$boletosF2 = $_POST['funcion2Hidden'];
if($boletosF2!=""){
$lugares2 = explode(" ", $boletosF2);
$cant2 = count($lugares2);
$cantTotal+=$cant2;

$f2 = "";
$sqlAP = "SELECT * FROM apartados";
if ($resultAP = mysql_query($sqlAP)) {
    while ($rowAP = mysql_fetch_array($resultApP)) {
        $f = $rowAP['funcion'];
        $lugar = $rowAP['lugar'];
        $count++;
        if ($f == "F2") {
            $f2.= ( $lugar . " ");
        }
    }
}
$sqlPag2 = "SELECT * FROM pagados";
if ($resultPag2 = mysql_query($sqlPag2)) {
    while ($rowPag2 = mysql_fetch_array($resultPag2)) {
        $f = $rowPag2['funcion'];
        $lugar = $rowPag2['lugar'];
        $count++;
        if ($f == "F2") {
            $f2.= ( $lugar . " ");
        }
    }
}
$func2 = explode(" ", $f2);
$cantUtilizados = count($func2);
for ($int = 0; $int < $cant2; $int++) {
    for ($r = 0; $r < $cantUtilizados; $r++) {
        if ($func2[$r] == $lugares2[$int]) {
            $repetidos++;
        }
    }
}
if ($repetidos > 0) {
    redirect("apartadoBoletos.php?error=1");
}
}
function redirect($url) {
    echo "<script language=\"JavaScript\"> window.location='$url'; </script>";
}
$totalAPagar=120*$cantTotal;

当我将它们保存到数据库并发送电子邮件时:

$boletosF1 = $_POST['boletosF1'];
$boletosF2 = $_POST['boletosF2'];
$nombre = $_POST['name'];
$correo = $_POST['mail'];
$cant1=0;
$cant2=0;
if($boletosF1!=""){
$lugares1 = explode(" ", $boletosF1);
echo $lugares1;
$cant1 = count($lugares1);
echo $cant1;
$f1 = "";
$sqlAP = "SELECT * FROM apartados";
if ($resultAP = mysql_query($sqlAP)) {
    while ($rowAP = mysql_fetch_array($resultApP)) {
        $f = $rowAP['funcion'];
        $lugar = $rowAP['lugar'];
        $count++;
        if ($f == "F1") {
            $f1.= ( $lugar . " ");
        }
    }
}
$sqlPag2 = "SELECT * FROM pagados";
if ($resultPag2 = mysql_query($sqlPag2)) {
    while ($rowPag2 = mysql_fetch_array($resultPag2)) {
        $f = $rowPag2['funcion'];
        $lugar = $rowPag2['lugar'];
        $count++;
        if ($f == "F1") {
            $f1.= ( $lugar . " ");
        }
    }
}
$func1 = explode(" ", $f1);
$cantUtilizados1 = count($func1);
$repetidos = 0;
for ($int = 0; $int < $cant1; $int++) {
    for ($r = 0; $r < $cantUtilizados1; $r++) {
        if ($func1[$r] == $lugares1[$int]) {
            $repetidos++;
        }
    }
}
if ($repetidos > 0) {

    redirect("apartadoBoletos.php?error=1");
}
}
if($boletosF2!=""){
$lugares2 = explode(" ", $boletosF2);
echo $lugares2;
$cant2 = count($lugares2);
echo $cant2;
$f2 = "";
$sqlAP = "SELECT * FROM apartados";
if ($resultAP = mysql_query($sqlAP)) {
    while ($rowAP = mysql_fetch_array($resultApP)) {
        $f = $rowAP['funcion'];
        $lugar = $rowAP['lugar'];
        $count++;
        if ($f == "F2") {
            $f2.= ( $lugar . " ");
        }
    }
}
$sqlPag2 = "SELECT * FROM pagados";
if ($resultPag2 = mysql_query($sqlPag2)) {
    while ($rowPag2 = mysql_fetch_array($resultPag2)) {
        $f = $rowPag2['funcion'];
        $lugar = $rowPag2['lugar'];
        $count++;
        if ($f == "F2") {
            $f2.= ( $lugar . " ");
        }
    }
}
$func2 = explode(" ", $f2);
$cantUtilizados2 = count($func2);
$repetidos = 0;
for ($int = 0; $int < $cant2; $int++) {
    for ($r = 0; $r < $cantUtilizados2; $r++) {
        if ($func2[$r] == $lugares2[$int]) {
            $repetidos++;
        }
    }
}
if ($repetidos > 0) {
    redirect("apartadoBoletos.php?error=1");
}
}
$rand = rand(0, 500);
$clave = sha1($rand . date("shd"));
$clave = substr($clave, 5, 5);
//insertar nuevo cliente
//mysql_query('BEGIN');
$sql = "INSERT INTO cliente(`idCliente`,`fecha`,`Nombre`,`correo`)VALUES('$clave',NOW(),'$nombre','$correo')";
$result = mysql_query($sql);
//crear arrays para guardar lugares
//insertar apartado F1

for ($i = 0; $i < $cant1; $i++) {
    $sqlF1 = "INSERT INTO apartados(`lugar`,`idCliente`,`funcion`)VALUES('$lugares1[$i]','$clave','F1')";
    $resultF1 = mysql_query($sqlF1);
}
for ($i = 0; $i < $cant2; $i++) {
    $sqlF1 = "INSERT INTO apartados(`lugar`,`idCliente`,`funcion`)VALUES('$lugares2[$i]','$clave','F2')";
    $resultF1 = mysql_query($sqlF1);
}

if (mysql_error ()) {
    //echo mysql_error ();
   // mysql_query('ROLLBACK');

    redirect("apartadoBoletos.php?error=2");
} else {
    $totalAPagar=($cant1+$cant2)*120;
   // mysql_query('COMMIT');
    $to = $correo;
    $dia=date("d-m-Y");
    //echo $dia;
    //User info
    $subject = "Boletos"; //The default subject. Will appear by default in all messages.
    //The message to be received in the inbox
    $msg .= "Estimad@ $nombre: \n\n";
    $msg .= "Clave:  $clave  " . "\r\n\n";  //the message itself
    $msg .= "Boletos 28 de Junio:  $boletosF1 " . "\r\n";
    $msg .= "Boletos 27 de Junio:  $boletosF2 " . "\r\n\n";
    $msg .= "Total a pagar:  $ $totalAPagar.00 " . "\r\n\n";
    //$header .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $header .= "From: no-reply@booking.com" . "\r\n";
    $header .= "Reply-To: no-reply@booking.com" . "\r\n";
    $header .= "Return-Path: $email" . "\r\n";

    mail($to, $subject, $msg, $header);
}

function redirect($url) {
    echo "<script language=\"JavaScript\"> window.location='$url'; </script>";
}

到目前为止,我找不到错误,我必须找到,因为这应该在昨天开始工作,但一切都必须停止 =/我真的需要帮助。

此外,我认为该错误可能与特定时间的用户数量有关,但可能会有所帮助,但由于它只是发生在某些使用它的人身上,我真的不能说这就是原因。

最佳答案

如果您不确定错误发生在何处,您可以添加大量的日志记录一段时间,看看您是否能弄清楚。

例如,当用户点击保存、购买门票或其他任何操作时,您可以将用户在表单上输入的数据写入日志文件。

然后,您可以在将购买信息发送到数据库时重新登录。记录SQL或存储过程名称和参数值。

这种大量的日志记录往往会损害性能,但当您处于绝境时,有时这是值得的。

一旦您对问题有所了解,或者认为您已经记录了足够的数据来进行分析,您就可以关闭记录。

关于php - 无法调试随机错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6237995/

相关文章:

php - 检索数据 Mysql/Php where 日期

php - Symfony 路由 : match anything after first node

php - 关于PHP对象性能的一些问题

mysql - 如何使用单个查询更新两行的交换值

mysql - 这个数据库规范化是否正确

php - Foreach inner When 查询 Laravel

php - 我无法从已经使用 GROUP BY 的表中循环记录

php - 尝试安装 Bright Game Panel (PHP/Apache)

php - session 销毁

mysql - MySql 中的间隔数据类型