<?php
//for testing
error_reporting(E_ALL);
// Include config file
//require_once 'config.php';
//for testing
$link = mysqli_connect("localhost", "root", "", "myblog");
// Define variables and initialize with empty values
$username = $password = $confirm_password = $first_name = $last_name = $email = $date_of_birth = $nic = $passport = $marital_state = $children = $residency = $height = $weight = $body_type = $appearance = $skin_colour = $ethnicity = $caste = $religion = $education = $career_sector = $mother_language = $occupation = $social_class = $drinking = $alcohol = $smoking = $diet = $family_values = $personality = $hobbies = $profile_posted_by = $about_me = "a";
$username_err = $password_err = $confirm_password_err = $first_name_err = $last_name_err = $email_err = $date_of_birth_err = $nic_err = $passport_err = $marital_state_err = $children_err = $residency_err = $height_err = $weight_err = $body_type_err = $appearance_err = $skin_colour_err = $ethnicity_err = $caste_err = $religion_err = $education_err = $career_sector_err = $mother_language_err = $occupation_err = $social_class_err = $drinking_err = $alcohol_err = $smoking_err = $diet_err = $family_values_err = $personality_err = $hobbies_err = $profile_posted_by_err = $about_me_err = "a";
// Processing form data when form is submitted
if ($_SERVER["REQUEST_METHOD"] == "GET") {
//validate firstname
if (empty(trim($_GET['first_name']))) {
$first_name_err = "Please enter first name.";
} else {
$first_name = trim($_GET['first_name']);
}
//validate lastname
if (empty(trim($_GET['last_name']))) {
$last_name_err = "Please enter last name.";
} else {
$last_name = trim($_GET['last_name']);
}
//validate email
if (empty(trim($_GET['email']))) {
$email_err = "Please enter email.";
} else {
$email = trim($_GET['email']);
}
//validate date of birth
if (empty(trim($_GET['date_of_birth']))) {
$date_of_birth_err = "Please enter date of birth.";
} else {
$date_of_birth = trim($_GET['date_of_birth']);
}
//validate nic
if (empty(trim($_GET['nic']))) {
$nic_err = "Please enter NIC.";
} else {
$nic = trim($_GET['nic']);
}
//validate passport
if (empty(trim($_GET['passport']))) {
$passport_err = "Please enter passport.";
} else {
$passport = trim($_GET['passport']);
}
//validate marital state
if (empty(trim($_GET['marital_state']))) {
$marital_state_err = "Please enter marital state.";
} else {
$marital_state = trim($_GET['marital_state']);
}
//validate children
if (empty(trim($_GET['children']))) {
$children_err = "Please enter children.";
} else {
$children = trim($_GET['children']);
}
//validate residency
if (empty(trim($_GET['residency']))) {
$residency_err = "Please enter residency.";
} else {
$residency = trim($_GET['residency']);
}
//validate height
if (empty(trim($_GET['height']))) {
$height_err = "Please enter height.";
} else {
$height = trim($_GET['height']);
}
//validate weight
if (empty(trim($_GET['weight']))) {
$weight_err = "Please enter weight.";
} else {
$weight = trim($_GET['weight']);
}
//validate body type
if (empty(trim($_GET['body_type']))) {
$body_type_err = "Please enter body type.";
} else {
$body_type = trim($_GET['body_type']);
}
//validate appearance
if (empty(trim($_GET['appearance']))) {
$appearance_err = "Please enter appearance.";
} else {
$appearance = trim($_GET['appearance']);
}
//validate skin colour
if (empty(trim($_GET['skin_colour']))) {
$skin_colour_err = "Please enter skin colour.";
} else {
$skin_colour = trim($_GET['skin_colour']);
}
//validate ethnicity
if (empty(trim($_GET['ethnicity']))) {
$ethnicity_err = "Please enter ethnicity.";
} else {
$ethnicity = trim($_GET['ethnicity']);
}
//validate caste
if (empty(trim($_GET['caste']))) {
$caste_err = "Please enter email.";
} else {
$caste = trim($_GET['caste']);
}
//validate religion
if (empty(trim($_GET['religion']))) {
$religion_err = "Please enter religion.";
} else {
$religion = trim($_GET['religion']);
}
//validate education
if (empty(trim($_GET['education']))) {
$eeducation_err = "Please enter education.";
} else {
$education = trim($_GET['education']);
}
//validate career sector
if (empty(trim($_GET['career_sector']))) {
$career_sector_err = "Please enter career sector.";
} else {
$career_sector = trim($_GET['career_sector']);
}
//validate mother language
if (empty(trim($_GET['mother_language']))) {
$mother_language_err = "Please enter mother language.";
} else {
$mother_language = trim($_GET['mother_language']);
}
//validate occupation
if (empty(trim($_GET['occupation']))) {
$occupation_err = "Please enter occupation.";
} else {
$occupation = trim($_GET['occupation']);
}
//validate social class
if (empty(trim($_GET['social_class']))) {
$social_class_err = "Please enter social class.";
} else {
$social_class = trim($_GET['social_class']);
}
//validate drinking
if (empty(trim($_GET['drinking']))) {
$drinking_err = "Please enter drinking.";
} else {
$drinking = trim($_GET['drinking']);
}
//validate alcohol
if (empty(trim($_GET['alcohol']))) {
$alcohol_err = "Please enter alcohol.";
} else {
$alcohol = trim($_GET['alcohol']);
}
//validate smoking
if (empty(trim($_GET['smoking']))) {
$smoking_err = "Please enter smoking.";
} else {
$smoking = trim($_GET['smoking']);
}
//validate diet
if (empty(trim($_GET['diet']))) {
$diet_err = "Please enter diet.";
} else {
$diet = trim($_GET['diet']);
}
//validate family values
if (empty(trim($_GET['family_values']))) {
$family_values_err = "Please enter famili values.";
} else {
$family_values = trim($_GET['family_values']);
}
//validate personality
if (empty(trim($_GET['personality']))) {
$personality_err = "Please enter personality.";
} else {
$personality = trim($_GET['personality']);
}
//validate hobbies
if (empty(trim($_GET['hobbies']))) {
$hobbies_err = "Please enter hobbies.";
} else {
$hobbies = trim($_GET['hobbies']);
}
//validate profile posted by
if (empty(trim($_GET['profile_posted_by']))) {
$profile_posted_by_err = "Please enter profile posted by.";
} else {
$profile_posted_by = trim($_GET['profile_posted_by']);
}
//validate about me
if (empty(trim($_GET['about_me']))) {
$about_me_err = "Please enter about me.";
} else {
$about_me = trim($_GET['about_me']);
}
// Validate username
if (empty(trim($_GET["username"]))) {
$username_err = "Please enter a username.";
} else {
$username = $_GET["username"];
// echo 'err';
// Prepare a select statement
$sql = "SELECT id FROM usersx WHERE username = ?";
if ($stmt = mysqli_prepare($link, $sql)) {
// Bind variables to the prepared statement as parameters
// removed
//$param_username = 'a';
mysqli_stmt_bind_param($stmt, "s", $username);
// Set parameters
//$param_username = trim($_GET["username"]);
//echo 'ee';
// Attempt to execute the prepared statement
if (mysqli_stmt_execute($stmt)) {
/* store result */
//echo 'e';
mysqli_stmt_store_result($stmt);
if (mysqli_stmt_num_rows($stmt) == 1) {
$username_err = "This username is already taken.";
} else {
$username = trim($_GET["username"]);
echo $username . '---';
}
} else {
echo "Oops! Something went wrong. Please try again later.";
}
//add here
mysqli_stmt_close($stmt);
} else {
echo("Error : " . mysqli_error($link));
}
//removed
//mysqli_stmt_close($stmt);
// Close statement
}
// Validate password
// if (empty(trim($_GET['password']))) {
// $password_err = "Please enter a password.";
// } elseif (strlen(trim($_GET['password'])) < 6) {
// $password_err = "Password must have atleast 6 characters.";
// } else {
// $password = trim($_GET['password']);
// }
// Validate confirm password
// if (empty(trim($_GET["confirm_password"]))) {
// $confirm_password_err = 'Please confirm password.';
// } else {
// $confirm_password = trim($_GET['confirm_password']);
// if ($password != $confirm_password) {
// $confirm_password_err = 'Password did not match.';
// }
// }
//removed
// Check input errors before inserting in database
// if (empty($username_err) && empty($password_err) && empty($confirm_password_err) && empty($first_name_err) && empty($last_name_err) && empty($email_err) && empty($date_of_birth_err) && empty($nic_err) && empty($marital_state_err) && empty($children_err) && empty($residency_err) && empty($height_err) && empty($weight_err) && empty($body_type_err) && empty($appearance_err) && empty($skin_colour_err) && empty($ethnicity_err) && empty($caste_err) && empty($religion_err) && empty($education_err) && empty($career_sector_err) && empty($mother_language_err) && empty($occupation_err) && empty($social_class_err) && empty($drinking_err) && empty($alcohol_err) && empty($smoking_err) && empty($diet_err) && empty($family_Values_err) && empty($personality_err) && empty($hobbies_err) && empty($about_me_err) && empty($profile_posted_by_err)) {
//for resting
echo 'in';
// Prepare an insert statement
// $sql = "INSERT INTO users (username, password, first_name, last_name, email, date_of_birth, nic, children, passport, marital_state, residency, height, weight, body_type, appearance, skin_colour, ethnicity, caste, religion, education, career_sector, mother_language, occupation, social_class, drinking, alcohol, smoking, diet, family_values, personality, hobbies, profile_posted_by, about_me) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
if ($stmt = mysqli_prepare($link, "INSERT INTO usersx (username, password, first_name, last_name, email, date_of_birth, nic, children, passport, marital_state, residency, height, weight, body_type, appearance, skin_colour, ethnicity, caste, religion, education, career_sector, mother_language, occupation, social_class, drinking, alcohol, smoking, diet, family_values, personality, hobbies, profile_posted_by, about_me) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "sssssssssssssssssssssssssssssssss", $param_username, $param_password, $param_first_name, $param_last_name, $param_email, $param_nic, $param_date_of_birth, $param_passport, $param_marital_state, $param_children, $param_residency, $param_height, $param_weight, $param_body_type, $param_appearance, $param_skin_colour, $param_ethnicity, $param_caste, $param_religion, $param_education, $param_career_sector, $param_mother_language, $param_occupation, $param_social_class, $param_drinking, $param_alcohol, $param_smoking, $param_diet, $param_family_values, $param_personality, $param_hobbies, $param_about_me, $param_profile_posted_by);
// Set parameters
$param_username = $username;
$param_first_name = $first_name;
$param_last_name = $last_name;
$param_email = $email;
$param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
$param_date_of_birth = $date_of_birth;
$param_nic = $nic;
$param_passport = $passport;
$param_marital_state = $marital_state;
$param_residency = $residency;
$param_height = $height;
$param_weight = $weight;
$param_body_type = $body_type;
$param_appearance = $appearance;
$param_skin_colour = $skin_colour;
$param_ethnicity = $ethnicity;
$param_caste = $caste;
$param_religion = $religion;
$param_education = $education;
$param_career_sector = $career_sector;
$param_mother_language = $mother_language;
$param_occupation = $occupation;
$param_social_class = $social_class;
$param_drinking = $drinking;
$param_alcohol = $alcohol;
$param_smoking = $smoking;
$param_diet = $diet;
$param_family_values = $family_values;
$param_personality = $personality;
$param_hobbies = $hobbies;
$param_about_me = $about_me;
$param_children = $children;
$param_profile_posted_by = $profile_posted_by;
echo 'in3';
// Attempt to execute the prepared statement
if (mysqli_stmt_execute($stmt)) {
// Redirect to login page
echo 'done';
//removed
// header("location: login.php");
} else {
echo "Something went wrong. Please try again later.";
}
mysqli_stmt_close($stmt);
}
mysqli_close($link);
// Close statement
// }else{
// echo 'validation error!';
// }
// Close connection
}
?>