-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsign_up.php
188 lines (158 loc) · 6.47 KB
/
sign_up.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
$servername = "localhost"; //Name of the server where database resides, ex: 127.0.0.1
$port_no = 3306; // Port number for Windows
$username = "user";
$password = "";
$myDB= "project"; //Name of the database to access
try {$conn = new PDO("mysql:host=$servername; port= $port_no, dbname=$myDB", $username, $password); //set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){echo "Connection failed: " . $e->getMessage();}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Sign Up</title>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
$pass=$_POST['pass'] ;
$confirm=$_POST['confirm'] ;
if($pass!==$confirm)
{
echo "<script>alert('enter same password in \"Confirm password\"')</script>";
}
if($_POST['userType']==='buyer')
{
$email = $_POST['email'];
$count = $conn->query("Select * from project.buyer a where a.buyerid =\"$email\"");
$exist = false;
while ($row=$count->fetch(PDO::FETCH_ASSOC)) {
foreach($row as $k => $val)
{
if($k=="pass")
$exist = true;
}
}
if($exist)
{
echo "<script>alert('email id already exist ')</script>";
}
try{
$sql="INSERT INTO project.buyer(buyerid,pass,name,phoneno,address)
VALUES (:email, :pass, :name, :phoneno,:address)";
$stmt=$conn->prepare($sql);
$stmt->execute(array(
':email' =>$_POST['email'],
':name' =>$_POST['name'],
':pass' =>$_POST['pass'],
':phoneno' =>$_POST['phoneno'],
':address' =>$_POST['address']
));
if($_POST['sub']=='pre')
{
$query="UPDATE project.buyer SET subid='PRE' where buyerid='{$_POST['email']}'";
$sql=$conn->prepare($query);
$sql->execute();
}
$cookie_name = "userName";
$cookie_value = $_POST["email"];
setcookie($cookie_name, $cookie_value);
header("Location:home.php");
exit;
}catch(PDOException $e){
echo $e;
}
}
else
{
$email = $_POST['email'];
$count = $conn->query("Select * from project.seller a where a.sellerid =\"$email\"");
$exist = false;
while ($row=$count->fetch(PDO::FETCH_ASSOC)) {
foreach($row as $k => $val)
{
if($k=="pass")
$exist = true;
}
}
if($exist)
{
echo "<script>alert('email id already exist ')</script>";
}
try{
$sql="INSERT INTO project.seller(sellerid,pass,name,phoneno,address)
VALUES (:email, :pass, :name, :phoneno,:address)";
$stmt=$conn->prepare($sql);
$stmt->execute(array(
':email' =>$_POST['email'],
':name' =>$_POST['name'],
':pass' =>$_POST['pass'],
':phoneno' =>$_POST['phoneno'],
':address' =>$_POST['address']
));
if($_POST['sub']==='pre')
{
$query="UPDATE project.seller SET subid='PRE' where sellerid='{$_POST['email']}'";
$sql=$conn->prepare($query);
$sql->execute();
}
$cookie_name = "userName";
$cookie_value = $_POST["email"];
setcookie($cookie_name, $cookie_value);
header("Location:seller.php");
exit;
}catch(PDOException $e){
echo $e;
}
}
}
?>
<div class="container">
<div class="column text-center"><h1>IITGbazaar</h1></div>
</div>
<form class="container-md shadow p-3 mb-5 bg-body rounded" method="post" action="signup.php">
<div class="mb3">
<label for="name" class="form-label">Name</label>
<input id="name" type="text" class="form-control" name="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" placeholder="name@iitg.ac.in" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="pass" required>
</div>
<div class="mb-3">
<label for="confirm" class="form-label"> Confirm Password</label>
<input type="password" class="form-control" id="confirm" name="confirm" required>
</div>
<div class="mb-3">
<label for="phone" class="form-label">PhoneNo</label>
<input type="text" class="form-control" id="phone" name="phoneno" required>
</div>
<div class="mb-3">
<label for="address" class="form-label">Address</label>
<input type="text" class="form-control" id="address" name="address" required>
</div>
<select class="form-select mb-5" name="userType">
<option value="buyer" selected>Buyer</option>
<option value="seller">Seller</option>
</select>
<select class="form-select mb-5" name="sub">
<option value="basic" selected>Basic</option>
<option value="pre">Premimum</option>
</select>
<div class='mb-3 '>
<input type="submit" class="btn btn-primary btn-lg btn-block" name="submit">
</div>
</form>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</body>
</html>