-
Notifications
You must be signed in to change notification settings - Fork 0
/
addcompany.php
63 lines (49 loc) · 2.38 KB
/
addcompany.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
<?php
//To Handle Session Variables on This Page
session_start();
//Including Database Connection From db.php file to avoid rewriting in all files
require_once("db.php");
//If user clicked register button
if(isset($_POST)) {
//Escape Special Characters In String First
$companyname = mysqli_real_escape_string($conn, $_POST['companyname']);
$headofficecity = mysqli_real_escape_string($conn, $_POST['headofficecity']);
$contactno = mysqli_real_escape_string($conn, $_POST['contactno']);
$website = mysqli_real_escape_string($conn, $_POST['website']);
$companytype = mysqli_real_escape_string($conn, $_POST['companytype']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$country = mysqli_real_escape_string($conn, $_POST['country']);
$state = mysqli_real_escape_string($conn, $_POST['state']);
$city = mysqli_real_escape_string($conn, $_POST['city']);
//Encrypt Password
$password = base64_encode(strrev(md5($password)));
//sql query to check if email already exists or not
$sql = "SELECT email FROM company WHERE email='$email'";
$result = $conn->query($sql);
//if email not found then we can insert new data
if($result->num_rows == 0) {
//sql new registration insert query
$sql = "INSERT INTO company(companyname, headofficecity, country, state, city, contactno, website, companytype, email, password) VALUES ('$companyname', '$headofficecity', '$country', '$state', '$city', '$contactno', '$website', '$companytype', '$email', '$password')";
if($conn->query($sql)===TRUE) {
//If data inserted successfully then Set some session variables for easy reference and redirect to company login
$_SESSION['registerCompleted'] = true;
header("Location: company-login.php");
exit();
} else {
//If data failed to insert then show that error. Note: This condition should not come unless we as a developer make mistake or someone tries to hack their way in and mess up :D
echo "Error " . $sql . "<br>" . $conn->error;
}
} else {
//if email found in database then show email already exists error.
$_SESSION['registerError'] = true;
header("Location: company-register.php");
exit();
}
//Close database connection. Not compulsory but good practice.
$conn->close();
} else {
//redirect them back to register page if they didn't click register button
header("Location: company-register.php");
exit();
}