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>
Ever tried to use
location.href = "pagina"
to redirect the chosen page?– Jhonatan Simões
Yes , but my page I return and by id , there on Location.href did not take I ID of the page
– Matheus Goes
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...– Jhonatan Simões
I tried so , but it does not come back in the same id ;/
– Matheus Goes
history.go is no solution to this, use a
header( 'location: /pagina/correta' );
followed by aexit();
(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 callingalert
PHP instead of showing the message on the page.– Bacco
What is the variable that keeps the Id you need on this page?
– Jhonatan Simões