I want to get a innertext value in my html to store it in my php variable. So far I have this.
This is my html code. I want to get innertext value of < p > which will show a float number calculated by my Javascript.
<!-- Total Price -->
<form method="post">
<div class="total-price-container">
Total Price: <p class="totalPrice"></p>
<button type="buy" name="buybutton" onclick="buyButtonClicked()">BUY</button>
</div>
</form>
In my php code I have this.
include 'html/cart.html';
// when buybutton clicked, sends the totalprice to sql database
if (isset($_POST['buybutton'])) {
// This will get the value of <p> and store it in totalPrice.
$totalPrice = $html->find("p[class=totalPrice]")[0]->innertext;
$sql = "INSERT INTO transaction (date, total_price) VALUES (now(), $totalPrice)";
I get Undefined variable error. What am I doing wrong?
buyButtonClicked()do? It needs to do Ajax or submit a form with the innerHTML copied to a form field