-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase_Task3.php
67 lines (51 loc) · 1.72 KB
/
Database_Task3.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
<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($username) {
$sql = "SELECT * FROM details where username LIKE '%$username'";
if (!$sql) {
echo mysql_error();
}
$result = mysql_query($sql);
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_array($result)) {
//print_r[$row];
echo "Username: " . $row["username"] . " " . "City: " . $row["city"] . "<br>";
}
} else {
echo "No results found";
}
}
//For Task 3, to prevent modification of string by user.
public function clean_String($str) {
return mysql_real_escape_string($str);
}
}
?>
</body>
</html>