addClass.php

back


<?php

require_once('dbConnect.php');

// Includes the connection class file for further use.

class addClass extends dbConnect {

// This class extends the dbConnect class from the above included dbConnect.php class file.
// This is needed to access the connection variable for further sql query.

public function addFunction($name) {

// This is the function which will insert the data provided by user to the database.
// This function takes the user submitted value as the argument.

$query="insert into oop_table values ('','".$name."')";

// Passing the sql query to the variable $query.

$result=$this->con->query($query);

// In dbConnect.php class file, $con variable is set as an object of the readymade mysqli class.
// query is the fuction of this class which takes the sql query as the argument.

if($result){

header('Location:index.php');

// In case the query is successful user is redirected to the index page.

}

}

}

?>