0
I’m trying to create a small sales system for a local store and I’m having trouble on the sales page, I was trying to learn how to use ajax to query product data in the mysql database of xampp and then return the value and name of the product, to be able to put the amount that is being sold and add with the other products that the customer is taking and in the end update the quantity in the database, however I am not able to pull the data from the database. I’d like a little help so I can see what’s wrong with the code. [! [The code displays a Warning saying that Undefined array key "codigoBarra"][1]][1]
SalesSale
Barcode:recoverProduct = () =>{ var product = new Xmlhttprequest(); var codigoBarra = Document.getElementById("codigoBarra"). value; var outcome = Document.getElementById("result"); open product("POST"+"sale.php? codeBarra="+codeBarra, true);
if(produto.readyState == 4){
if(produto.status == 200){
result.innerHTML = xmlreq.responseText;
}
else{
result.innerHTML = "Erro: " + xmlreq.statusText;
}
}
produto.send("venda.php");
};
include('conecta.php');
$codigoBarra = $_POST['codigoBarra'];
$sql = "select nome, valor from produto where codigoDeBarra = ?";
$resultado = $pdo->prepare($sql);
$resultado->execute();
$vetor=$resultado->fetchall(PDO::FETCH_OBJ);
foreach($vetor as $linha){
echo $linha->nome."--".$linha->valor;
}
?>
Here’s the html, javascript and php code I’m using. the database used is phpmyadmin’s mysql. table structure: id_product int not null auto_increment, Code to sweep up, name varchar, int amount, double value.
If anyone can help I would be very grateful ! [1]: https://i.stack.Imgur.com/auF45.png
Is the code complete? By q you don’t seem to be passing the variable
$codigoBarra
for your query. Is missing$resultado->bindValue()
probably. Take a look here– andre_luiss