I have two PHP files that I have set up on an online web hosting platform in order to integrate the database into my android application. Whenever I run the URL : https://wounding-pat.000webhostapp.com/register.php in order to test if the register.php code is running correctly, I get the following messages on my browser.
Connection Successful
Notice: Undefined index: name in /storage/ssd2/158/3185158/public_html/register.php on line 5
Notice: Undefined index: email in /storage/ssd2/158/3185158/public_html/register.php on line 6
Notice: Undefined index: password in /storage/ssd2/158/3185158/public_html/register.php on line 7
Notice: Undefined index: subject in /storage/ssd2/158/3185158/public_html/register.php on line 8
Notice: Undefined index: counsellor in /storage/ssd2/158/3185158/public_html/register.php on line 9
Notice: Undefined variable: connection in /storage/ssd2/158/3185158/public_html/register.php on line 13
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /storage/ssd2/158/3185158/public_html/register.php on line 13
Error
The following is my init.php code
<?php
$host = "localhost";
$database = "id3185158_csetestonlinedb";
$username = "id3185158_root";
$password = "admin";
//$con = mysqli_connect($host, $username, $password, $database);
if (mysqli_connect($host, $username, $password, $database)) {
echo "Connection Successful";
} else {
echo "Connection Unsuccessful";
}
?>
The following is my register.php code
<?php
require "init.php";
$name = $_POST["name"];
$email = $_POST["email"];
$password = $_POST["password"];
$subject = $_POST["subject"];
$counsellor = $_POST["counsellor"];
$sql_query = "insert into teachers values('$name', '$email', '$password', '$subject', '$counsellor');";
if (mysqli_query($connection, $sql_query)) {
echo " Data Inserted";
} else {
echo " Error";
}
?>