0
I’m trying to upload the data from a form to the database. I have data coming from POST and also from GET, but when clicking on the Submit button the value of the variable that receives data from GET is reset.
THIS IS THE FORM.
<form action="pedidos.php" method="post">
<table border="1">
<tr>
<td> NOME DO CLIENTE </td>
<td> <?php echo strtoupper($nome_cliente); ?> </td>
</tr>
<tr>
<td> PRODUTO: </td>
<td> <select name="produto">
<?php
if(isset($selecionar_produto) && mysql_num_rows($selecionar_produto)){
while($produto = mysql_fetch_array($selecionar_produto)){ ?>
<option value="<?php echo $produto["id_produto"]; ?>"> <?php echo $produto["nome_produto"]; ?> </option>
<?php
}
}
?>
<tr>
<td> QUANTIDADE: </td>
<td> <input type="number" name="qtde"> </td>
</tr>
<tr>
<td> RUA: </td>
<td> <?php echo strtoupper($rua); ?> </td>
</tr>
<tr>
<td> NÚMERO </td>
<td> <?php echo strtoupper($num); ?> </td>
</tr>
<tr>
<td> BAIRRO </td>
<td> <?php echo strtoupper($bairro); ?> </td>
</tr>
<tr>
<td> CIDADE: </td>
<td> <?php echo strtoupper($cidade); ?> </td>
</tr>
<tr>
<td> STATUS </td>
<td>
<select name="status">
<?php
if(isset($selecionar_status) && mysql_num_rows($selecionar_status)){
while($status = mysql_fetch_array($selecionar_status)){ ?>
<option value="<?php echo $status["id_status"];?>"> <?php echo $status["status"]; ?> </option>
<?php
}
}
?>
</td>
</tr>
<tr>
<td colspan="2"> <input type="submit" name="botao" value="Cadastrar">
<a href="painel.php"> <input type="button" name="botao" value="Voltar"> </a>
</td>
</tr>
</select>
</td>
</tr>
</table>
</form>
THIS IS PHP TO REGISTER THE REQUEST
if (isset($_POST["botao"]) && $_POST["botao"] == "Cadastrar"){
$gravar_pedidos = mysql_query("INSERT INTO pedidos(id_cliente,id_produto,id_status) values ('$id_cliente','$produto','$status')");
if(!$gravar_pedidos){
echo "Erro ".mysql_error();
}else{
echo "<meta http-equiv='refresh' content='0;URL=painel.php'/>
<script type=\"text/javascript\">
alert(\"Operação Realizada com sucesso!!\");
</script> ";
}
}
edit the question by placing the html form code so that we can see how it is and see if the problem consists of the form or your script. As soon as you edit the question, you comment here and I take a look and see what I can help you with.
– CloudAC
$id_cliente = (isset($_GET["id_cliente"]));
is not correct. Since you will only be withtrue
orfalse
. What you want to do is$id_cliente = ($_GET["id_cliente"]);
– Isac
Copy and paste into your question how is the html of your form, and when you mix get and post I think it is best to use the method that recovers both $_REQUEST['xxx']. [ http://php.net/manual/en/reserved.variables.request.php ]
– Wilson Rosa Gomes
how do I use $_REQUEST? because I’m using the post and get
– sol25lua
If any answer fits, mark it as accepted. See how and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252