deleteClass.php

back


<?php

require_once('dbConnect.php');

// Includes the connection class file for further use.

class deleteClass extends dbConnect{

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

public function deleteFunction($id){

// This is the function which will delete a row of data in the database uniquely identified by $id.
// For this the function takes $id as argument.

$query="delete oop_table.* from oop_table where oop_table.id=".$id;

// 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, $result is set and thus user is redirected to index.php.

}

else{

echo 'something is wrong';

// In case the query is not successful, $result is not set and above message is displayed.

}

}

}

?>