-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.php
More file actions
64 lines (55 loc) · 2.01 KB
/
server.php
File metadata and controls
64 lines (55 loc) · 2.01 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
<?php
/**
* File Name : server.php
* File Path : C:\xampp\htdocs\PHP
* Description : PHP file to insert the form data into table
* Created date : 23/01/2019
* @Author : Mukesh
* Comments : The data entered through form is sent to MySQL database.
*/
//connect to the database
$errors = 0;
include("constants.php");
$db = mysqli_connect(SERVER, USER, PASSWORD, DB);
// receive all input values from the form
$firstname = mysqli_real_escape_string($db, $_POST['firstname']);
$middlename = mysqli_real_escape_string($db, $_POST['middlename']);
$lastame = mysqli_real_escape_string($db, $_POST['lastname']);
$gender = mysqli_real_escape_string($db, $_POST['gender']);
$birthdate = mysqli_real_escape_string($db, $_POST['birthdate']);
$phone = mysqli_real_escape_string($db, $_POST['phone']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$addr = mysqli_real_escape_string($db, $_POST['addr']);
$password1 = mysqli_real_escape_string($db, $_POST['password1']);
$password2 = mysqli_real_escape_string($db, $_POST['password2']);
$about = mysqli_real_escape_string($db, $_POST['about']);
foreach($_POST as $key => $value)
{
if (empty($value))
{
$errors += 1;
}
}
if (empty($middlename))
{
$errors = 0;
}
if ($errors == 0)
{
$password1 = password_hash($password1, PASSWORD_BCRYPT);
$password2 = password_hash($password2, PASSWORD_BCRYPT);
$sql = "INSERT INTO user (firstname, middlename, lastname, gender, birthdate, phone, email, addr, password1, password2, about) VALUES ('$firstname',
'$middlename', '$lastame', '$gender', '$birthdate', '$phone', '$email', '$addr', '$password1', '$password2', '$about')";
if ($db->query($sql) === TRUE){
echo "<p style='color:white;'> Registration successfull</p>";
}
else
{
echo "<p style='color:red;'>Error:".mysqli_error($db)."</p>";
}
}
else
{
echo "Registration not allowed.";
}
?>