html - Retrieving div contents from a php page and posting to a database

I have a form in a page called;products.php
whose details I'd like to send to the database including the contents ofclass='stars'
exactly as is in its HTML format, I thought the code in the form action;review.php
would solve it but I'm met by an error:Fatal error: Uncaught Error: Call to undefined function file_get_html() in /Library/WebServer/Documents/TUTP/review.php:8 Stack trace: #0 {main} thrown in /Library/WebServer/Documents/TUTP/review.php on line 8
. What is the best way of retrieving the div star and sending it to my database the way I'm doing with the contents of the input?
<?php
echo "
<form action='reviews.php' method='POST'>
<div class='stars'>
<i class='fas fa-star star'></i>
<i class='fas fa-star star'></i>
<i class='fas fa-star star'></i>
<i class='fas fa-star star'></i>
<i class='fas fa-star star'></i>
</div>
<input class='reviewIn' type='text' name='reviewPost' placeholder='Enter review'>
<button type='submit' name='submitR'>POST</button>
</form>";
<!-- reviews.php -->
<?php
if (isset($_POST['submitR'])) {
include_once "db.php";
$html = file_get_html('product.php');
$stars = $html->find('.stars');
$title=mysqli_real_escape_string($conn,$_GET['title']);
$reviewPost = $_POST['reviewPost'];
echo $html;
$sql = "SELECT * FROM reviews;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL statement failed 1!";
}else{
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$rowCount = mysqli_num_rows($result);
$sql = "INSERT INTO reviews(reviewsField,itemName,starRating) VALUES (?,?,?);";
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL statement failed 2!";
}else{
mysqli_stmt_bind_param($stmt,"sss",$reviewPost,$title,$stars);
mysqli_stmt_execute($stmt);
}
}
}
Answer
Solution:
You need to download PHP HTML Dom parser and include it.
include_once('simple_html_dom.php');
$html = file_get_html('product.php');
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: property [id] does not exist on this collection instance.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.