0% found this document useful (0 votes)
19 views

Project Oop

The document describes creating a database and tables using PHP to store and retrieve book information. It includes PHP classes to initialize the database connection, create tables, insert, retrieve, update and delete book records.

Uploaded by

Jhanine Rhosales
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Project Oop

The document describes creating a database and tables using PHP to store and retrieve book information. It includes PHP classes to initialize the database connection, create tables, insert, retrieve, update and delete book records.

Uploaded by

Jhanine Rhosales
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

MLG COLLEGE OF LEARNING INC.

BRGY. ATABAY HILONGOS,LEYTE

PROJECT IN OBJECT OR

SUBMITTED BY: JANINE R.ROSALES BSIT-2


INSTRUCTOR: MR. MARNITO M. MAHINLO
db.php

<?php

class Database

public $conn;

public $servername="localhost";

public $username="root";

public $password="";

public $dbname="anin";

public function init()

$this->conn=new mysqli($this->servername,$this->username,$this->password);

$create="CREATE DATABASE IF NOT EXISTS $this->dbname";

$this->conn->query($create);

$use="USE $this->dbname";

$this->conn->query($use);

var_dump($this->conn->error);

create.php

<?php

include 'db.php';

class Table extends Database

public $tblname = "books";


public function createTable()

$this->init();

$tbl = "CREATE TABLE IF NOT EXISTS $this->tblname

(id int auto_increment primary key,

book_name text,

description text

)";

$this->conn->query($tbl);

var_dump($this->conn->error);

public function insert($bn,$d)

$in = "INSERT INTO $this->tblname (book_name, description)

values('$bn','$d')";

$this->conn->query($in);

var_dump($this->conn->error);

public function getAll()

$s = "SELECT * FROM $this->tblname";

return $this->conn->query($s);

public function delete ($id)

$d = "DELETE FROM $this->tblname WHERE id='$id'";

$this->conn->query($d);

}
public function f_all($q)

$all = $this->conn->query("SELECT * FROM $this->tblname WHERE id='$q'");

return $all->fetch_assoc();

public function updatetbl($t,$r,$l)

$updatetbl = "UPDATE $this->tblname SET book_name='$t', description='$r'

WHERE id='$l'";

return $this->conn->query($updatetbl);

inserts.php

<?php

include 'create.php';

$t = new Table;

$t->createTable();

$t->insert($_GET['book'],$_GET['description']);

header ('location: formanine.php');

?>

delete.php

<?php

include 'create.php';

$n = new Table;

$n->createTable();

$n->getAll();

$n->delete($_GET['id']);

header('location: formanine.php');
update.php

<?php

include 'create.php';

$update = new Table;

$update->createTable();

$names = $update->getAll();

$lists = $names->fetch_all(MYSQLI_ASSOC);

foreach($lists as $anine)

$update->updatetbl($_GET['b'],$_GET['des'],$_GET['id']);

header('location: formanine.php');

updateform.php

<?php

include 'create.php';

$up = new Table;

$up->createTable();

$j = $up->getAll();

$ls = $j->fetch_all(MYSQLI_ASSOC);

$list = $up->f_all($_GET['id']);

?>

<form method ="GET" action = "update.php">

BOOK NAME:<br>

<input type = "text" name = "b" value = "<?php echo $list['book_name']?>"><br>

DESCRIPTION:<br>

<input type = "text" name = "des" value = "<?php echo $list['description']?>"><br>

<input type ="hidden" name= "id" value = "<?php echo $_GET['id'] ?>">
<input type="submit" value="ENTER"><br>

<table border = 2 width = 500>

<th>ID</th>

<th>Book Name</th>

<th>Description</th>

<tbody>

<?php foreach($ls as $lang) { ?>

<tr>

<td><?php echo $lang['id'] ?></td>

<td><?php echo $lang['book_name'] ?></td>

<td><?php echo $lang['description'] ?></td>

</tr>

<?php }?>

</tbody>

</table>

</form>

formanine.php

<?php

include 'create.php';

$d = new Table;

$d->createTable();

$item=$d->getAll();

$f=$item->fetch_all(MYSQLI_ASSOC);

?>

<form method = "get" action = "inserts.php">

BOOK NAME:<br>
<input type = "text" name = "book"><br>

DESCRIPTION:<br>

<input type = "text" name = "description"><br>

<input type="submit" value="ENTER">

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

</head>

<body>

<table border=2 width=500>

<th>id</th>

<th>book_name</th>

<th>description</th>

<th>delete</th>

<th>update</th>

<tbody>

<?php foreach($f as $janine){?>

<tr>

<td>

<?php echo $janine['id']?>

</td>

<td>

<?php echo $janine['book_name']?>


</td>

<td>

<?php echo $janine['description']?>

</td>

<td> <center><a href = "delete.php?id=<?php echo $janine['id']; ?>">delete</a></center></td>

<td> <center><a href = "updateform.php?id=<?php echo $janine['id'];


?>">update</a></center></td>

</tr>

<?php }?>

</tbody>

</table>

</body>

</html>

You might also like