Report display by customer input value

Asked

Viewed 24 times

-1

I want it to show me the amount the customer enters in the quantity field.

HTML code:

    <style>
    header form input { display: block; margin-top:10px;  }
</style>
<header>
<form action="etiqueta.php" method="POST">
<input type="text" placeholder="Nome do Produto" name="nomeproduto">
<input type="text" placeholder="Outra Informação" name="outrainformacao">
<input type="text" placeholder="Marca" name="marca">
<input type="text" placeholder="Quantidade" name="quantidade"><BR>
<button>Carregar Etiquetas</button>
</form>
</header>

This is the tag code.php

<?php


 $nomeproduto = $_POST['nomeproduto'];
 $outrainformacao = $_POST['outrainformacao'];
 $marca = $_POST['marca'];
 $quantidade = $_POST['quantidade'];

 $quantidademaxima = 4;

 while($quantidade >= $quantidademaxima) {

        echo "$nomeproduto e $outrainformacao e $marca e $quantidade";

        $quantidade++;

 }

I want the amount that the client typed in the form field to be displayed in the tag code.php . Can you please help me.

  • You’re already doing it. What’s the difficulty?

  • When I enter the value, it loops

  • If the value is greater than 4 you will loop as long as it is greater than 4, incrementing with each iteration. That is, it will always be greater than 4 and the loop never ends.

  • @Andersoncarloswoss. Yes, I understood. However, it has some possibility to display only what the user type ?

  • @Andersoncarloswoss When I put the value == It works, however, above 4 does not work.

  • Because it goes into infinite loop... you just review your logic and define exactly what you need to do.

  • Just a hunch, it’s not mandatory or definitive, but where $quantidade++; do $quantidade--;.

  • @Augustovasques Thank you young man, it worked.

  • PS: Maybe for an exercise it is enough, but if the code is commercial I think it is not the best solution. Personally I think the way would be to inform the user that the value extrapolated the stock and return the focus on the front end to the input that selects the quantity with the value at the maximum available. I suggested the $quantidade--; only to direct thought.

Show 4 more comments

1 answer

1

Just put it this way:

<?php
 $nomeproduto = $_POST['nomeproduto'];
 $outrainformacao = $_POST['outrainformacao'];
 $marca = $_POST['marca'];
 $quantidade = $_POST['quantidade'];
 $quantidademaxima = 1;

    while($quantidade >= $quantidademaxima) {

            echo "$nomeproduto e $outrainformacao e $marca e $quantidade". "<br>";

            $quantidade--;

     }

Browser other questions tagged

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