Trying to display Rand() after inserting in db

Asked

Viewed 52 times

0

Hello,

I’m trying to display a random number with Rand() after inserting it into the database. mysql insertion works normally, but when I try to display a message with the $request variable nothing is shown.

If I insert something into the database using a variable this variable becomes empty after insertion?

Here is the code.

<?php 
$codigo = $_POST['codigo'];
$produto = $_POST['produto'];
$valor = $_POST['valor'];
$pedido = rand(1,400);

if (insereProduto($conexao, $codigo, $produto, $valor, $pedido)) { ?>
	<div class="alert alert-danger" role="alert">
		<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
		Pedido salvo com sucesso!
	</div>
	<?php
} else { ?>
	<div class="alert alert-success" role="alert">
		<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
		Pedido salvo com sucesso!,  O numero do pedido é <?php= $pedido; ?>
	</div>
<?php
}
 ?>
 <br />
<button class="btn btn-warning" onClick="javascript:window.location.href='novo-pedido.php'">Fazer novo pedido</button>

  • 2

    Or do you use <?php echo $pedido? > or you use <?= ?> both ways are correct. I believe that’s the problem there. You’re using <?php= $pedido ?>.

  • Thank you, that’s right!

  • "Rafaéis" post the answer and accept so that if someone has the same doubt find faster.

No answers

Browser other questions tagged

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