-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess.php
More file actions
60 lines (46 loc) · 1.49 KB
/
Copy pathprocess.php
File metadata and controls
60 lines (46 loc) · 1.49 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
<?php
$errors = array(); // array to hold validation errors
$data = array(); // array to pass back data
// validate the variables ========
if (empty($_POST['user_name']))
$errors['user_name'] = 'Name is required.';
if (empty($_POST['user_phone']))
$errors['user_phone'] = 'Phone is required.';
if (empty($_POST['user_password']))
$errors['user_password'] = 'Password is required.';
// return a response ==============
// response if there are errors
if ( ! empty($errors)) {
// if there are items in our errors array, return those errors
$data['success'] = false;
$data['errors'] = $errors;
} else {
$name = $_POST['user_name'];
$phone = $_POST['user_phone'];
$pass = $_POST['user_password'];
$servername = "XXXXX";
$username = "XXXXX";
$password = "XXXXX";
$dbname = "XXXX";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO user (name, phone, password)
VALUES ('$name', '$phone', '$pass')";
if ($conn->query($sql) === TRUE) {
// if there are no errors, return a message
$data['lastId'] = $conn->insert_id;
$data['success'] = true;
$data['message'] = 'New record created successfully!';
} else {
echo
$data['success'] = false;
$data['message'] = "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
// return all our data to an AJAX call
echo json_encode($data);