-
Notifications
You must be signed in to change notification settings - Fork 4
/
register.php
35 lines (28 loc) · 915 Bytes
/
register.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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "signup";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get form data
$Username= $_POST['Username'];
$age= $_POST['age'];
$dob= $_POST['dob'];
$contact= $_POST['contact'];
//fill all the fields
if(empty($_POST['Username']) || empty($_POST['age']) || empty($_POST['dob']) || empty($_POST['contact'])){
echo json_encode( array('message' => 'fill all the fields') );
exit();
}
// Insert data into MySQL table
$sql = "INSERT INTO register (Username, age, dob, contact) VALUES ('$Username', '$age', '$dob', '$contact')";
if ($conn->query($sql) === TRUE) {
echo json_encode( array('success' => true) );
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>