I am working on a wordpress site, and started implanting a CRUD database. I coded out an example that works perfectly on my localhost. However, I am working with file mangaer in cpanel, and am having difficulty with changing the regular database query to a one that is incorporated with $wpdb. I have tried to use $wpdb->get_results(), but I get the same error. Any help would be greatly appreciated.
Here is my code:
// CONNECTION TO DATABASE
$query = "SELECT * FROM students";
$query_results = mysqli_query($wpdb->dbh, $query) or die(mysqli_error($wpdb->dbh));
if(mysqli_num_rows($query_results) > 0)
{
foreach($query_run as $student)
{
?>
echo '
<form id="saveStudent">
<tr>'
echo '<td>'<?php $student->id; ?> echo '</td>';
echo '<td>'<?php $student->first_name; ?> echo '</td>';
echo '<td>'<?php $student->last_name; ?> echo '</td>';
echo '<button type="button" class="btn btn-danger">Delete Student</button>'
echo '</tr>';
<?php
}
}
?>
EDIT: The error message I get is Warning: mysqli_query() expects parameter 1 to be mysqli, null given
global $wpdb;before trying to use the global$wpdbobject?