-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusersAdd.php
More file actions
97 lines (84 loc) · 3.31 KB
/
usersAdd.php
File metadata and controls
97 lines (84 loc) · 3.31 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
//workoutTrackerInsert.php
// Include config file
require_once 'config.php';
// Define variables and initialize with empty values
$email = $gender = $height = $addess = $age = $name = "";
$email_err = $gender_err = $height_err = $addess_err = $age_err = $name_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Validate email
if(empty(trim($_POST["email"]))){
$email_err = "Please enter a email.";
}
else{
$email = trim($_POST['email']);
}
// Validate weight
if(empty(trim($_POST['gender']))){
$gender_err = "Please enter a gender.";
}else{
$gender = trim($_POST['gender']);
}
if(empty(trim($_POST['height']))){
$height_err = "Please enter a height.";
}else{
$height = trim($_POST['height']);
}
if(empty(trim($_POST['address']))){
$address_err = "Please enter a address.";
}else{
$address = trim($_POST['address']);
}
if(empty(trim($_POST['age']))){
$age_err = "Please enter a age.";
}else{
$age = trim($_POST['age']);
}
if(empty(trim($_POST['name']))){
$name_err = "Please enter a name.";
}else{
$name = trim($_POST['name']);
}
// Check input errors before inserting in database
if(empty($email_err) && empty($gender_err) && empty($height_err) && empty($address_err)&& empty($age_err) && empty($name_err)){
// Prepare an insert statement
$sql = "INSERT INTO workout_users (email, gender, height, address, age, name) VALUES (?, ?, ?, ?, ?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ssssss", $param_email, $param_gender, $param_height, $param_address, $param_age, $param_name);
// Set parameters
$param_email = $email;
$param_gender = $gender;
$param_height = $height;
$param_address = $address;
$param_age = $age;
$param_name = $name;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Redirect to login page
header("location: indexLogin.html");
} else{
echo "Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// Close connection
mysqli_close($link);
if(!(empty($email_err))){
header("location: indexUser.html?u_err=".$email_err); // send error message in the err variable
}else if(!(empty($gender_err))){
header("location: indexUser.html?p_err=".$gender_err); // change the html to the one you need to show
}else if(!(empty($height_err))){
header("location: indexUser.html?p_err=".$height_err); // change the html to the one you need to show
}else if(!(empty($address_err))){
header("location: indexUser.html?p_err=".$address_err); // change the html to the one you need to show
}else if(!(empty($age_err))){
header("location: indexUser.html?p_err=".$age_err); // change the html to the one you need to show
}else if(!(empty($name_err))){
header("location: indexUser.html?p_err=".$name_err); // change the html to the one you need to show
}
}
?>