I want to use a mysqli prepared statement to display data into an html table.However when I run the code I get a blank page. The code is presented below.
<?php
include_once 'includes/db_connect.php';
?>
<?php
if($stmt = $mysqli->prepare("SELECT id first_name second_name , request , purpose, description
FROM data_centre_users WHERE status <> 'approved'")){
$stmt->execute(); // Execute the prepared query.
$stmt->store_result();
// get variables from result.
$stmt->bind_result($id , $first_name, $second_name ,$request , $purpose , $description );
function myDate($x){
if ( !strtotime($x)) {
return "00-00-0000 00:00:00";
}
else{
return strftime('%Y-%m-%dT%H:%M:%S',
strtotime($x));
}
return "";
}
?>
<section id="content">
<div class="scroll-table">
<table >
<caption>
</caption>
<thead>
<tr>
<th class="center"><strong>Name</strong></th>
<th class="center"><strong>Request</strong></th>
<th class="center"><strong>Purpose</strong></th>
<th class="center"><strong>Description</strong></th>
<th class="center"><strong>Approve</strong></th>
<th class="center"><strong>Delete</strong></th>
</tr>
</thead>
<?php
if($stmt->num_rows > 0){
// output data of each row
while($stme->fetch()){ ?>
<tbody>
<tr>
<td class="center"><?php echo $first_name." ".$last_name; ?></td>
<td class="center"><?php echo $request; ?></td>
<td class="center"><?php echo $purpose; ?></td>
<td class="center"><?php echo $description; ?></td>
<td class="center" ><a href="javascript:if(confirm('Are you sure you want to approve?')){ location.href='approve.php?id=<?php echo $id; ?>'; }">approve</a></td>
<td class="center" ><a href="javascript:if(confirm('Are you sure you want to delete?')){ location.href='deny.php?id=<?php echo $id; ?>'; }">deny</a></td>
</tr>
</tbody>
<?php
}
}
?>
</table>
</div>
</section>
<?php } ?>
<?php
?>
This is the code for the database connection.
<?php
include_once 'psl-config.php'; // Needed because functions.php is not included
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
if ($mysqli->connect_error) {
header("Location: ../error.php?err=Unable to connect to MySQL");
exit();
}
This is the script for the table.
CREATE TABLE IF NOT EXISTS `data_centre_users` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`first_name` varchar(120) NOT NULL,
`last_name` varchar(120) NOT NULL,
`request` varchar(200) NOT NULL,
`purpose` varchar(200) NOT NULL,
`description` varchar(200) NOT NULL,
`booking_time` datetime(6) NOT NULL,
`access_time` datetime(6) NOT NULL,
`exit_time` datetime(6) NOT NULL,
`status` varchar(35) NOT NULL DEFAULT 'not yet',
`approved_by` varchar(150) NOT NULL,
`accessed_by` varchar(16) NOT NULL,
`time_approved` datetime(6) NOT NULL,
`task_completed` varchar(16) NOT NULL,
`time_completed` datetime(6) NOT NULL,
`time_started` datetime(6) NOT NULL,
`department` varchar(250) NOT NULL,
`unit` varchar(140) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=76 ;
--
-- Dumping data for table `data_centre_users`
--
INSERT INTO `data_centre_users` (`id`, `first_name`, `last_name`, `request`, `purpose`, `description`, `booking_time`, `access_time`, `exit_time`, `status`, `approved_by`, `accessed_by`, `time_approved`, `task_completed`, `time_completed`, `time_started`, `department`, `unit`)
VALUES
(6, 'kazare', 'Jaguar', 'rautine maintenance', 'Unofficial', 'dust and clean', '2015-08-07 04:34:12.000000', '2015-08-10 02:50:00.000000', '1970-01-01 01:00:00.000000', 'approved', 'SYSTEM', 'Staff', '2015-08-10 09:22:09.000000', 'completed', '2015-08-13 09:30:57.000000', '0000-00-00 00:00:00.000000', '', ''),
When I run the code I get a blank (empty) page.
After adding the following code to the php.ini file from this page , 'ini_set('display_errors', 1);' 'ini_set('display_startup_errors', 1);' 'error_reporting(E_ALL);'
The following error is displayed.
Fatal error: Class 'mysqli' not found in C:\wamp\www\datacentre\admin\includes\db_connect.php on line 4
Any help.