Update page after sending the form

Asked

Viewed 4,260 times

1

Good guys may seem something simple , but I’m not getting , I have an Insert page that works perfectly , after I do the Insert I use the

<script>
history.go(-2) 
</script>

for back two pages back and on this page lists my table items , but when it comes back it seems that the page does not update so does not appear my new table item , for it to appear I need to update the page , would have as after I send the form update dps back the pages ?

My entire code :

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link  type="text/javascript" href="jquery.js">
<link type="text/javascript" href="post.js">
<link  type="text/javascript" href="jquery-form.js">
<body >
<form action="" method="post" enctype="multipart/form-data">
    <fieldset>
        <?php
        ini_set('default_charset','UTF-8');



        if(isset($_POST['send'])){
            $produtos = $_POST['produtos'];
            $id_venda = $_POST['id_venda'];


            include ('banco.php');

            mysql_query("INSERT INTO pedido(id, produtos, id_venda )
            values(
                NULL,
                '{$produtos}',
                '{$id_venda}'
                              )
            ");

            echo  '<script>history.go(-2) </script>';
        }

        ?>
        <legend style="color: #ffffff" class="btn btn-inverse">Cadastro </legend>

        <?php
        ini_set('default_charset','UTF-8');

        mysql_connect('127.0.0.1','root','');

        mysql_select_db('mecanica');

        $query='Select * from produtos';

        ?>


        <label for="produtos" style="color: #000"><strong>Produto : </strong></label>
        <select name="produtos" style="width: 400px">
            <?php
            //execução da query
            $resultado=mysql_query($query);


            while($linha=mysql_fetch_array($resultado))
            {

                echo '<option  value="' . $linha['id_produto'] . '">' . $linha['produtos'] . '</option>';
            }
            echo '</select>';
            ?>
        </select><br><br>

        <?php   $id_ven  = $_GET["id_venda"];    ?>

        <script type="text/javascript">

            function mostra() {
                if (document.getElementById('ocultar').style.display == 'block'){
                    document.getElementById('ocultar').style.display = 'none';
                }else {document.getElementById('ocultar').style.display = 'block'}
            }

        </script>


        <div id="ocultar" style="visibility: hidden" >

    <?php
        ini_set('default_charset','UTF-8');

        mysql_connect('127.0.0.1','root','');

        mysql_select_db('mecanica');

        $query='Select * from pedido';
        ?>


        <label for="id_venda" style="color: #000"><strong>ID VENDA : </strong></label>
        <select name="id_venda" style="width: 75px">
            <?php
           $resultado=mysql_query($query);
            while($linha=mysql_fetch_array($resultado))
            {

            }
            echo '<option >' . $_GET['id_venda'] . '</option>';

            echo '</select>';
            ?>
        </select><br><br>


        </div>


        <input type="submit" class="btn btn-inverse" value="Enviar" name="send">
        <a href="listadevendas.php" class="btn btn-inverse">Cancelar</a>
    </fieldset>
</form>
</body>
</html>
  • 3

    Ever tried to use location.href = "pagina" to redirect the chosen page?

  • Yes , but my page I return and by id , there on Location.href did not take I ID of the page

  • 2

    Well, you could use it location.href = "pagina.php?id=111" passing the ID by GET, if you have it on your current page... If do not make it be received on this page, otherwise I know no other way...

  • I tried so , but it does not come back in the same id ;/

  • 1

    history.go is no solution to this, use a header( 'location: /pagina/correta' ); followed by a exit(); (but before displaying data on the screen). And avoid calling PHP Javascript. Pretty much everywhere you find it, it’s something you don’t know what you’re doing (there may be some exception, but so far I haven’t seen any). For you to have an idea, there are people who come to the point of calling alert PHP instead of showing the message on the page.

  • What is the variable that keeps the Id you need on this page?

Show 1 more comment

2 answers

3


after the data insert use the PHP header function.

header('Location:url_da_pagina'), to be redirected to the page.

  • Remembering that it has to refactor the code, because Location will only work if it has not put anything in the HTML yet.

0

Good I can solve like this:

header("location:cabecalho.php?&id={$id} ");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.