I can’t enter data numbers float

Asked

Viewed 79 times

-2

<?php 
    require_once('cabecalho.php'); 
    require_once('conn.php'); 
?>
<?php
    $nome = $_REQUEST["nome"];
    $preco = $_REQUEST["preco"];              
    $query = "insert into produtos (nome, preco) values ('{$nome}', '{$preco}')";
    if(mysqli_query($conn, $query)){ ?>
    <p class="alert-success">Produto <?= $nome ?> <?= $preco ?> adicionado.</p>
    <?php } else { ?>
    <p class="alert-danger">Produto <?= $nome; ?> não foi adicionado.</p>    
    <?php } ?>   
        </header>
    </section>
<?php include('rodape.php'); ?>
  • 3

    Try to use the mysqli_error to display an error message that is useful to you in development.

  • "I can’t get into the database" is somewhat vague/generic, since this may have many different causes. Can be values are of a different type than defined in the bank, or outside the allowed values (exceeded maximum size, is null when the column does not allow, etc etc etc), or anything else. Please click on the [Edit] link just below the question tags and add more information (table structure, data to be entered, error message, etc.), because the way it is, we have no way to guess. Try to make the question contain a [mcve]

1 answer

1

Maybe the problem is in the connection or in the SQL command, try to make the SQL command this way to see if it works:

$query ="INSERT INTO prudutos (nome,preco)VALUES ('$nome','$preco')";
  • When the integer is right. When the float is wrong. In the table this decimal is defined (10,2)

  • Actually the problem is the comma. What can I do ?

  • I saw that I was doing a lot of wrong things. In my first mistake, it was not setting the price input with 'number'. And after defining as 'number' I discovered the step attribute of html 5. I set it to 'step='0.01' and it worked.

Browser other questions tagged

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