Function PHP Yes Send mail but sometimes Do not save the data in MySQL

0

I have the following function:

    function pedido(){
        global $db, $username, $usua, $logo, $footer_correo;

        // Datos recibidos del Formulario
        $monto          = $_POST['monto'];
        $banco_emisor       = $_POST['banco_emisor'];
        $banco_destino      = $_POST['banco_destino'];
        $nro_transf         = $_POST['nro_transf'];
        $ci_nro_cuenta      = $_POST['ci_nro_cuenta'];
        $fecha_transf       = $_POST['fecha_transf'];

        $user = $_SESSION['user']['username'];

        $status_pedido ="ESPERANDO";

    $verf = "SELECT nro_transf FROM pedidos WHERE nro_transf = '$nro_transf'";
    $result = mysqli_query($db, $verf);
    $rows =  mysqli_num_rows($result);

    $verf2 = "SELECT nro_transf FROM pagos WHERE nro_transf = '$nro_transf'";
    $result2 = mysqli_query($db, $verf2);
    $rows2 =  mysqli_num_rows($result2);

    $sumarows = $rows + $rows2;

        if ($sumarows>0){
            $_SESSION['msn_pedidos']  = '<i class="fa fa-exclamation-triangle fa-fw"></i> Lo sentimos, el numero de transferencia que intenta utilizar ya fue utilizado.<br>';
            //mysqli_close($db);
        } else {

$query = "INSERT INTO pedidos (id, usuario, monto, nro_transf, banco_emisor, banco_destino, fecha_transf, ci_nro_cuenta, status_pedido) 
VALUES(null, '$user', '$monto', '$nro_transf', '$banco_emisor', '$banco_destino', '$fecha_transf', '$ci_nro_cuenta', '$status_pedido')";

    if (mysqli_query($db, $query)){
        $_SESSION['msn_pedidos']  = "Se ha registrado su pedido de manera Exitosa.<br>";



        $email = $_SESSION['user']['email'];
        $nombre = $_SESSION['user']['nombre'];
        $asunto = "Pedido Tarjetas UN1CA";
        $cuerpo = "Hola $nombre <br><br>
        Usted ha registrado un pago de manera exitosa por un monto de: $monto BsS <br>
    Desde el banco: $banco_emisor <br>
    Hacia nuestra cuenta en el: $banco_destino <br>
        Numero de operacion: $nro_transf <br>
    Efectuado el $fecha_transf.<br>";
        enviarEmail($email, $nombre, $asunto, $cuerpo); 
        $_SESSION['msn_pedidos']  .= '<i class="fa fa-envelope"></i> Hemos enviado Un correo con el resumen de su pedido';

        } else {
        $_SESSION['msn_pedidos']  = '<i class="fa fa-exclamation-triangle"></i>Algo ha ocurrido, intente efectuar su declaracion nuevamente.';     
        }
    }
    }

The problem: Apparently my tests work without a problem. In fact, several people here helped me to correct and optimize my function but at this moment there are already several users who report that the email arrives but your data is not recorded in the database, I would like to help me determine if it is an error in my code, and if so, tell me some way to correct so that the phenomenon I just explained does not continue to happen. I'm thinking it might be server error but I'd like to discard my code first.

    
asked by Jose M Herrera V 10.11.2018 в 13:17
source

0 answers