I received the following message when executing the included code:
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\diff\selecttesttable.php on line 28
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\diff\selecttesttable.php on line 30
and have spent several hours trying to find the problem with no success
The code is:
<?php
// connect to the database
// include('connect-db_belmont.php');
// server info
$server = 'localhost';
$user = 'root';
$pass = '';
$db = 'belmont';
// connect to the database using object oriented style
$mysqli = new mysqli($server, $user, $pass, $db);
// show errors (remove this line if on a live site)
// mysqli_report(MYSQLI_REPORT_ERROR);
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT owner_name FROM assessor");
while($row = mysqli_fetch_array($result))
{
// echo $row['FirstName'] . " " . $row['LastName'];
// echo "<br>";
$owner=$row['owner_name'];
// echo "This is the variable ".$owner."<br />";
// echo $row['owner_name'];
preg_match('/^([^ ]+) (.*?)(?: & (.*))?$/', $row['owner_name'], $matches);
// echo " - Last name: {$matches[1]} - Husband: {$matches[2]}<br />";
$last = $matches[1];
$first = $matches[2];
$_SESSION['last'] = $matches[1];
echo "session variable last equals ".$matches[1];
echo " last variable is ".$last."<br />";
$first = $matches[2];
$_SESSION['first'] = $matches[2];
echo "session variable first equals ".$matches[2];
echo " first variable is ".$first."<br />";
if(isset($matches[3])) {
$mate = $matches[3];
echo " - Mate: {$matches[3]}";
}
echo "<br />";
}
// mysqli_close($con);
?>
Line 28 is: $result = mysqli_query($con,"SELECT owner_name FROM assessor"); I have also tried changing from owner_name to * with same results
Line 30 is: while($row = mysqli_fetch_array($result)) {
Please help