In my registration page When I try to register a new person with the registration page I get this Notice/Warning message:
// Create a connection to the logindb database. // Set the encoding and the access details as constants: DEFINE ('DB_USER', 'william'); DEFINE ('DB_PASSWORD', 'kat0nlap'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'logindb'); // Make the connection: $dbcon = new mysqli('DB_HOST', 'DB_USER', 'DB_PASSWORD', 'DB_NAME'); // Set the encoding...optional but recommended mysqli_set_charset($dbcon, 'utf8');
Notice: Undefined variable: dbcon in C:\xampp\htdocs\login\register-page.php on line 36
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\login\register-page.php on line 36
The notice/warning is repeated for each element where mysqli_real_escape_string is used.
The relevant first section of the registration page is as follows:
<!doctype html>
<html lang=en>
<head>
<title>Register page</title>
<meta charset=utf-8><!--important prerequisite for escaping strings -->
<link rel="stylesheet" type="text/css" href="styles.css">
<style type="text/css">
p.error { color:red; font-size:105%; font-weight:bold; text-align:center; }
</style>
</head>
<body>
<div id="container">
<header>
<?php include("register-header.php"); ?>
</header>
<nav>
<?php include("nav.php"); ?>
</nav>
<aside>
<?php include("info-col.php"); ?>
</aside>
<div id="content"><!-- Start of the page content. -->
<p>
<?php
// This script performs an INSERT query that adds a record to the users table.
// If the form was filled out the PHP code is executed
if ($SERVER['REQUEST_METHOD'] == 'POST') {
try { // moved here for escape_strings
require ('mysqli_connect.php'); // moved for require escape strings
$errors = array(); // Initialize an error array.
// --------------------Validate first name-------------
// Was the first name entered?
if (empty($POST['fname'])) {
$errors[] = 'You did not enter your first name.';
}
else { $fn = mysqli_real_escape_string($dbcon, trim($_POST['fname']));
}