I’m having trouble inserting data into a table with php

Asked

Viewed 48 times

1

My form is like this:

<form name="pedidooo" action="cadastrandoPedido.php" method="post" >

    <?php
    include './conex.php';

    $query = ("SELECT * FROM conta");
    $result = $mysqli->query($query);
    echo '<gg>Numero da Conta:<gg>';
    echo "<select name='conta'>";
    while ($fetch = $result->fetch_assoc()) {
        $value = $fetch['NR_CONTA'];
        echo "<option>";
        echo ($value);
        echo "</option>";
    }
    echo "</select>";
    echo"<br>";
    echo"<br>";

    $query = ("SELECT * from itemcardapio");
    $result = $mysqli->query($query);
    echo '<gg>Numero do Item do cardápio:</gg>';
    echo "<select name='item'>";
    while ($fetch = $result->fetch_assoc()) {
        $valu = $fetch['NR_ITEM'];
                        echo "<option>";
        echo ($valu);

        echo "</option>";
    }
    echo "</select>";
    echo"<br>";
    echo"<br>";

    echo "</select>";
    echo"<br>";

    $query = ("SELECT * from itemcardapio");
    $result = $mysqli->query($query);
    echo '<gg>Numero do Item do cardápio:</gg>';
    echo "<select name='preco'>";
    while ($fetch = $result->fetch_assoc()) {
        $value = $fetch['PRECO'];
         echo "<option>";
        echo ($value);

        echo "</option>";
    }
    echo "</select>";
    echo"<br>";
    echo"<br>";
    ?>
    Quantidade: <input type="number" name="quantidade" value="1" /><br><
    <button type="submit">Fazer Pedido</button> <br></center>

</form>

The action page of my aphorium is as follows::

<?php
include './conex.php';

$valor=0;
$item=$_POST['item'];
$conta=$_POST['conta'];
$quant=$_POST['quantidade'];
$preco=$_POST['preco'];
$valor=$valor+($preco*$quant);

$qr = $mysqli->query( "INSERT INTO pedido (NR_CONTA, NR_ITEM, QUANTIDADE, PRECO_UNITARIO) values( '$conta', '$item', '$quant', '$valor)");

echo'<link href="style.css" rel="stylesheet" type="text/css"/>';
echo "<gg>Pedido cadastrado com sucesso!<gg>";
echo "<gg>Total: !</gg>";
echo "<gg>$valor</gg>";

?>

inserir a descrição da imagem aqui

The problem is she doesn’t put it in the bank...

conex.php

<?php
$servidor="localhost";
$usuario="root";
$senha="";
$bd="obaratao";

$mysqli=new mysqli($servidor, $usuario, $senha, $bd);

if (mysqli_connect_errno()){ die ('Algum probleminha....'.mysqli_connect_errno());
 exit();
}

?>
  • It’s all right in conex.php?

  • Good morning, it’s all right, because I can insert it in other tables of the database, edited and put the class conex.php

  • 2

    Note that your INSERT lacks a single quotation mark on $valor.

  • Oh man I love you! Thank you so much, that’s all I need to do at work, now to holiday kk... thanks!

No answers

Browser other questions tagged

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