-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask2.php
83 lines (65 loc) · 2.24 KB
/
Task2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<html>
<head>
<title>Database Connectivity</title>
</head>
<body>
<?php
class Database {
public $host;
public $username;
public $password;
public $database;
public $con;
function Database() {
$this->host = "localhost";
$this->username = "root";
$this->password = "root";
$this->database = "Users";
}
public function connect() {
$this->con = mysql_connect($this->host, $this->username, $this->password);
if (!$this->con) {
echo mysql_error();
}
$sel = mysql_select_db($this->database, $this->con);
if (!$sel) {
echo mysql_error();
}
}
public function select() {
$sql = "SELECT * FROM coupons";
if (!$sql) {
echo mysql_error();
}
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
// print_r[$row];
echo "Coupon: " . $row["coupon"] . " " . "<br>";
}
}
public function search($coupon) {
$query = "SELECT * FROM coupons WHERE coupon LIKE '%$coupon%'";
if (!$query) {
echo mysql_error();
}
$result = mysql_query($query);
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_array($result)) {
echo "Coupon: " . $row["coupon"] . " " . "Offer: " . $row["offer"] . "<br>";
}
} else {
echo "No results found!";
}
}
public function insert($coupon, $offer) {
$sql = mysql_query("INSERT INTO coupons(coupon,offer) VALUES('$coupon','$offer')");
if (!$sql) {
echo mysql_error();
} else {
echo "Offer inserted successfully!";
}
}
}
?>
</body>
</html>