-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
47 lines (39 loc) · 1.76 KB
/
signup.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
<?php
error_reporting(E_ALL); ini_set('display_errors', '1');
require_once('config.php');
$connection = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME);
if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error);
}
session_start();
// Validate the input data
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$firstname =mysqli_real_escape_string($connection, $_POST['firstname']);
$lastname = mysqli_real_escape_string($connection, $_POST['lastname']);
$email = mysqli_real_escape_string($connection, $_POST['email']);
$phone = mysqli_real_escape_string($connection, $_POST['phone']);
$username = mysqli_real_escape_string($connection, $_POST['username']);
$password = mysqli_real_escape_string($connection, $_POST['password']);
// Check if the username and email already exist
$query = "SELECT * FROM BUYER WHERE username = '$username' OR email = '$email'";
$result = mysqli_query($connection, $query);
if (mysqli_num_rows($result) > 0) {
// Username or email already exists, display error message
$message = "Error: Username or email already exists.";
echo $message;
} else {
// Insert the new user into the database
$query = "INSERT INTO BUYER (username, password,firstname,lastname,email,phone) VALUES ('$username', '$password','$firstname','$lastname', '$email','$phone')";
$result = mysqli_query($connection, $query);
if ($result) {
// Sign up successful, display success message
$message = "User registered successfully!";
echo $message;
} else {
// Sign up failed, display error message
$message = "Error: " . mysqli_error($connection);
echo $message;
}
}
}
?>