After submit in a popup and insert in bbdd I get a blank page

0

I have a modal that when I give Save it saves me in BBDD (mysql), the insert is stored in bbdd correctly but I get a blank screen when I simply want the modal to close.

Any ideas?

My code is all in the same file, I pass the code to you.

PHP

<?php

require "../db/configdb.php";

$mh = $_POST['cod_mh'];

if (isset($_POST["cod_mh"]))
{
    try 
    {
        $sql = "INSERT INTO mh(codigo_mh) VALUES ('".$_POST['cod_mh']."');";
        $result = mysql_query($sql);
        if (!$result) {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }
    }

    catch(PDOException $error) 
    {
        echo $sql . "<br>" . $error->getMessage();
    }
    $connextion->close();
}
?>

HTML / BOOTSTRAP

<div class="modal fade" id="MHModal">
            <div class="modal-dialog">
                <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">....</h4>
                </div>
                <div class="modal-body">
                    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
                        <div class="form-group">
                            <label for="cod_mh" class="control-label">Código MH</label>
                            <input type="text" class="form-control" name="cod_mh">
                        </div>

                    <button type="submit" class="btn btn-primary btn-md" id="submit_mh">Guardar</button>
                    <button type="button" class="btn btn-default btn-md" data-dismiss="modal">Salir</button>
                    </form>
                </div>
                </div>
            </div>
        </div>
    
asked by David M. 02.12.2017 в 20:45
source

1 answer

0

You just need to redirect the site to a specific route, for this we use header () :

<?php

require "../db/configdb.php";

$mh = $_POST['cod_mh'];

if (isset($_POST["cod_mh"]))
{
    try 
    {
        $sql = "INSERT INTO mh(codigo_mh) VALUES ('".$_POST['cod_mh']."');";
        $result = mysql_query($sql);
        if ($result) {
            header("location: ruta_de_la_pagina.html");
        }else{
            echo "Error: " . $sql . "<br>" . $conn->error;
        }
    }

    catch(PDOException $error) 
    {
        echo $sql . "<br>" . $error->getMessage();
    }
    $connextion->close();
}
?>
    
answered by 02.12.2017 в 20:51