I am calling this script using ajax in php page But it gives me this error .I am not able to figure out the problem.Kindly guide.
This is the error
Fatal error: Uncaught Error: Call to undefined method PDOStatement::fetch_assoc() in C:xampphtdocstestsmscheck_purpose.php:15
Stack trace:
#0 {main}
thrown in C:xampphtdocstestsmscheck_purpose.php on line 15
<?php
require_once("includes/config.php");
// code user email availablity
if(isset($_POST['purpose'])) {
$purpose = $_POST['purpose'];
// Prepare a SQL statement to fetch products based on the selected category
$sql = "SELECT * FROM tblstationerytype WHERE purpose = '$purpose'";
// Execute the query
$result = $dbh->query($sql);
// Generate HTML options for products
$options = "<option value=''>Select Product</option>";
while($row = $result->fetch_assoc()) {
$options .= "<option value='{$row['id']}'>{$row['stationerytype']}</option>";
}
// Output options
echo $options;
}
?>