Skip to content

Commit 8c448a5

Browse files
committed
Class 14 added
1 parent 1a5fa43 commit 8c448a5

34 files changed

+1874
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/**
4+
*
5+
*/
6+
class Database
7+
{
8+
9+
public $host = DB_HOST;
10+
public $user = DB_USER;
11+
public $pass = DB_PASS;
12+
public $dbname = DB_NAME;
13+
14+
public $link;
15+
public $error;
16+
17+
public function __construct(){
18+
$this->connectDB();
19+
}
20+
private function connectDB(){
21+
$this->link = new mysqli($this->host,$this->user,$this->pass,$this->dbname);
22+
if (!$this->link) {
23+
$this->error = "Connection failed ".$this->link->connect_error;
24+
return false;
25+
}
26+
}
27+
// select or read data
28+
29+
public function select($query){
30+
$result = $this->link->query($query) or die($this->link->error.__LINE__);
31+
if ($result->num_rows>0) {
32+
return $result;
33+
}else{
34+
return false;
35+
}
36+
}
37+
// Insert Data
38+
public function insert($query){
39+
$insert_row = $this->link->query($query) or die($this->link->error.__LINE__);
40+
if($insert_row){
41+
header("Location: index.php?msg=".urlencode('Data Insert successfully'));
42+
exit;
43+
} else{
44+
45+
die ("Error : (" .$this->link->errno.")".$this->link->error);
46+
}
47+
}
48+
49+
// Update Data
50+
public function update($query){
51+
$update_row = $this->link->query($query) or die($this->link->error.__LINE__);
52+
if($update_row){
53+
header("Location: index.php?msg=".urlencode('Data Updated successfully'));
54+
exit;
55+
} else{
56+
57+
die ("Error : (" .$this->link->errno.")".$this->link->error);
58+
}
59+
}
60+
61+
// Update Data
62+
public function delete($query){
63+
$delete_row = $this->link->query($query) or die($this->link->error.__LINE__);
64+
if($delete_row){
65+
header("Location: index.php?msg=".urlencode('Data Deleted successfully'));
66+
exit;
67+
} else{
68+
69+
die ("Error : (" .$this->link->errno.")".$this->link->error);
70+
}
71+
}
72+
73+
}//end Database Class
74+
75+
?>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
6+
define("DB_HOST", "localhost");
7+
define("DB_USER", "root");
8+
define("DB_PASS", "");
9+
define("DB_NAME", "oop-crud");
10+
11+
12+
?>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
include "inc/header.php";
3+
include "config.php";
4+
include "Database.php";
5+
?>
6+
7+
<?php
8+
$db = new Database();
9+
if(isset($_POST['submit'])){
10+
$name = mysqli_real_escape_string($db->link, $_POST['name']);
11+
$email = mysqli_real_escape_string($db->link,$_POST['email']);
12+
$skill = mysqli_real_escape_string($db->link,$_POST['skill']);
13+
if($name=="" || $email == "" || $skill == ""){
14+
$error = "Field must not be Empty!!";
15+
}else{
16+
17+
$query = "INSERT INTO tbl_users(name,email,skill)VALUES('$name','$email','$skill')";
18+
$create =$db->insert($query);
19+
}
20+
}
21+
?>
22+
23+
<div class="container">
24+
<div class="row">
25+
<div class="col-md-10 col-md-offset-1">
26+
<?php
27+
if(isset($error)){
28+
echo "<span class='alert alert-danger fade in'>".$error."</span>";
29+
30+
}
31+
?>
32+
<div class="add-form">
33+
<form class="form-horizontal" action="" method="post">
34+
<div class="form-group">
35+
<label for="inputName" class="control-label col-xs-2">Name</label>
36+
<div class="col-xs-10">
37+
<input type="text" name="name" class="form-control" id="inputName" placeholder="Name">
38+
</div>
39+
</div>
40+
<div class="form-group">
41+
<label for="inputEmail" class="control-label col-xs-2">Email</label>
42+
<div class="col-xs-10">
43+
<input type="email" name="email" class="form-control" id="inputEmail" placeholder="Email">
44+
</div>
45+
</div>
46+
<div class="form-group">
47+
<label for="inputSkill" class="control-label col-xs-2">Skill</label>
48+
<div class="col-xs-10">
49+
<input type="text" name="skill" class="form-control" id="inputSkill" placeholder="Skill">
50+
</div>
51+
</div>
52+
<div class="form-group">
53+
<div class="col-xs-offset-2 col-xs-10">
54+
<button type="submit" name="submit" class="btn btn-primary">Insert</button>
55+
<button type="reset" class="btn btn-danger">Cancel</button>
56+
</div>
57+
</div>
58+
</form>
59+
<a href="index.php" class="btn btn-info">Go Back</a>
60+
</div>
61+
</div>
62+
</div>
63+
</div>
64+
65+
<?php
66+
include "inc/footer.php";
67+
?>

Class-14-15-09-2020/OOPHP-CRUD/inc/css/bootstrap.min.css

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Class-14-15-09-2020/OOPHP-CRUD/inc/css/font-awesome.min.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
body{
3+
margin: 0;
4+
padding: 0
5+
6+
}
7+
.header-area{
8+
background: #460000;
9+
color: #fff;
10+
margin-bottom: -10px;
11+
}
12+
.header-area a{
13+
text-decoration:none;
14+
color:#fff;
15+
16+
}
17+
.main-content table{
18+
margin-top:25px;
19+
}
20+
.header-area h1{
21+
font-size: 60px;
22+
font-weight: 900;
23+
text-shadow: 2px 2px 4px #ff4500;
24+
padding: 20px 0;
25+
}
26+
27+
.main-content{
28+
padding: 30px 20px;
29+
border-right: 2px solid #460000;
30+
border-left: 2px solid #460000;
31+
}
32+
table tr th{
33+
34+
text-align: center;;
35+
}
36+
.footer-area{
37+
background: #460000;
38+
color: #fff;
39+
padding: 20px;
40+
}
41+
.mygroup a{
42+
color: #fff;
43+
text-shadow: 2px 1px 1px antiquewhite;
44+
text-decoration: none;
45+
}
46+
.mygroup a:hover{
47+
color: #ff4500;
48+
}
49+
.social-link i {
50+
border: 2px solid orange;
51+
border-radius: 50%;
52+
color: orange;
53+
font-size: 22px;
54+
height: 50px;
55+
padding: 12px;
56+
width: 50px;
57+
margin-right: 20px;
58+
}
59+
.social-link i:hover{
60+
background: #eee;
61+
color: orange;
62+
border: 2px solid #eee;
63+
64+
}
65+
.add-form {
66+
margin-top: 50px;
67+
border: 2px solid #eee;
68+
padding: 47px 20px;
69+
}
120 KB
Binary file not shown.
73.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)