i have a registration form and i want to store the information (gender and phone included) but it didnt store in the database even the register is successful but the column for gender and phone_number are blank
– I had tried to change my structure of gender from ENUM “MALE”, “FEMALE” to varchr(50) also not work
CREATE TABLE `users` (
`id` int(11) NOT NULL,
`full_name` varchar(100) NOT NULL,
`nickname` varchar(50) NOT NULL,
`user_id` varchar(50) NOT NULL,
`gender` varchar(50) NOT NULL,
`age` int(11) NOT NULL,
`address` varchar(255) NOT NULL,
`email` varchar(100) NOT NULL,
`phone_number` varchar(20) NOT NULL,
`country` varchar(50) NOT NULL,
`user_type` varchar(50) NOT NULL,
`program` varchar(100) NOT NULL,
`department` varchar(50) DEFAULT NULL,
`password` varchar(255) NOT NULL,
`avatar_url` varchar(255) DEFAULT NULL,
`registration_date` timestamp NOT NULL DEFAULT current_timestamp()
)
20, 'AFLRED', 'CEO of MDIS', 'DCT-1151', '', 69, '54,Jalan Impian 20', '[email protected]', '', 'MY', 'STAFF', '', 'OFFICE OF THE REGISTER', '$2y$10$JJZVYp5DQ7QC6SMT0zYQC.Eq84gJtW8ATwhBxTWExE1xW5EQ.nVTG', './uploads/MDIS-badge.png', '2024-07-23 17:04:20'),
my phone number and gender are not being record
<?php
session_start();
$conn = new mysqli("localhost", "root", "", "forum");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$avatar_url = null; // Initialize $avatar_url
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Sanitize and validate inputs
$full_name = $conn->real_escape_string($_POST['full_name']);
$nickname = $conn->real_escape_string($_POST['nickname']);
$user_id = $conn->real_escape_string($_POST['user_id']);
$gender = $conn->real_escape_string($_POST['gender']);
$age = (int)$_POST['age'];
$address = $conn->real_escape_string($_POST['address']);
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ? $_POST['email'] : "";
$phone_number = preg_match("/^[0-9]{10,15}$/", $_POST['phone_number']) ? $_POST['phone_number'] : "";
$country = $conn->real_escape_string($_POST['country']);
$user_type = $conn->real_escape_string($_POST['user_type']);
$program = $conn->real_escape_string($_POST['program']);
$department = $conn->real_escape_string($_POST['department'] ?? '');
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
// Handle file upload
if (isset($_FILES['avatar_url']) && $_FILES['avatar_url']['error'] == UPLOAD_ERR_OK) {
$fileTmpPath = $_FILES['avatar_url']['tmp_name'];
$fileName = $_FILES['avatar_url']['name'];
$fileSize = $_FILES['avatar_url']['size'];
$fileType = $_FILES['avatar_url']['type'];
$fileNameCmps = explode(".", $fileName);
$fileExtension = strtolower(end($fileNameCmps));
// Set allowed file extensions
$allowedExts = array('jpg', 'jpeg', 'png', 'gif');
if (in_array($fileExtension, $allowedExts)) {
// Move file to destination directory
$uploadFileDir = './uploads/';
$dest_path = $uploadFileDir . $fileName;
if (move_uploaded_file($fileTmpPath, $dest_path)) {
// Store file path in $avatar_url
$avatar_url = $dest_path;
} else {
$_SESSION['error'] = 'Error moving the file.';
header("Location: register page.php");
exit();
}
} else {
$_SESSION['error'] = 'Invalid file type.';
header("Location: register page.php");
exit();
}
}
// Check password match
if ($password !== $confirm_password) {
$_SESSION['error'] = 'Passwords do not match.';
header("Location: register page.php");
exit();
}
// Hash the password
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Prepare and execute statement to check if user_id already exists
$stmt = $conn->prepare("SELECT COUNT(*) FROM users WHERE user_id = ?");
$stmt->bind_param("s", $user_id);
$stmt->execute();
$stmt->bind_result($count);
$stmt->fetch();
$stmt->close();
if ($count > 0) {
$_SESSION['error'] = 'ID already exists. Please use a different ID.';
header("Location: register page.php");
} else {
// Prepare and execute statement to insert user data
$stmt = $conn->prepare("INSERT INTO users (full_name, nickname, user_id, gender, age, address, email, phone_number, country, user_type, program, department, password, avatar_url) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssissssssssss", $full_name, $nickname, $user_id, $gender, $age, $address, $email, $phone_number, $country, $user_type, $program, $department, $hashed_password, $avatar_url);
// Execute the statement
if ($stmt->execute()) {
header("Location: index.html");
exit();
} else {
$_SESSION['error'] = "Error: " . $stmt->error;
header("Location: register page.php");
}
$stmt->close();
}
$conn->close();
}
?>
i want my gender can be display either male or female in database and the phone_number also can be display in varchar