-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_user.php
More file actions
103 lines (80 loc) · 2.91 KB
/
add_user.php
File metadata and controls
103 lines (80 loc) · 2.91 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<html>
<head>
<center> <h1>Library Management System</h1> </center>
<link rel="stylesheet" type="text/css" href="style.css">
<title> Library Management System </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h2><left><a href="Page1.html">Homepage</a></left></h2>
<div id="header">
<form name="adduser" method="post" action="add_user.php">
<center><table cellspacing="5">
<tr>
<td></td>
<td><h1> Add User </h1></td>
</tr>
<tr>
<td>First Name: </td>
<td> <input type="text" id="f_name" name="f_name"/> </td>
</tr>
<tr>
<td>Last Name: </td>
<td> <input type="text" id="l_name" name="l_name"/> </td>
</tr>
<tr>
<td>Address: </td>
<td> <textarea rows="3" cols="20" id="address" name="address"></textarea> </td>
<tr>
<td>Phone No.:
<br> Format (000)-000-0000
</td>
<td> <input type="text" id="phone" name="phone"/> </td>
</tr>
<tr>
<td></td>
<td> <input type="submit" name="add" value="Add"/></td>
</tr>
</table></center>
</form>
</div>
<?php
$con = mysql_connect("localhost", "root", "");
if ($con) {
mysql_select_db("library");
} else {
echo 'could not connect' . "<br/>";
}
if ($_POST) {
if (isset($_POST['add'])) {
add_user();
}
}
function add_user() {
$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$queryuser = "select count(*) as no_times from borrower"
. " where fname LIKE '$f_name' AND lname LIKE '$l_name' AND address LIKE '$address'";
$records = mysql_query($queryuser);
while($chk = mysql_fetch_assoc($records))
{
if($chk['no_times']>=1)
{
echo "<script type='text/javascript'>alert('USER ALREADY PRESENT');</script>";
exit();
}
}
$query = "insert into borrower(fname,lname,address,phone) values('$f_name','$l_name','$address','$phone');";
mysql_query($query);
if ($query === FALSE) {
echo mysql_error();
} else {
echo "<script type='text/javascript'>alert('USER ADDED');</script>";
}
}
?>
</body>
</html>