File "signupForm.php"
Full Path: /home/scheduling/public_html/function/signupForm.php
File size: 1.29 KB
MIME-type: text/x-php
Charset: utf-8
<?php
include "../include/conn.php"; // Include your database connection file
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get the data from the form
$fullname = $_POST['fullname'];
$age = $_POST['age'];
$gender = $_POST['gender'];
$studentID = $_POST['studentID'];
$username = $_POST['username'];
$password = $_POST['password'];
$year = $_POST['year'];
$status = "Deactivated"; // Set default status to Active
// Check for duplicate username
$stmt = $conn->prepare("SELECT COUNT(*) FROM student WHERE username = ?");
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($count);
$stmt->fetch();
$stmt->close();
if ($count > 0) {
echo "Username already exists.";
exit;
}
// Prepare the insert statement
$stmt = $conn->prepare("INSERT INTO student (fullname, age, gender, student_id, username, password, year, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sissssss", $fullname, $age, $gender, $studentID, $username, $password, $year, $status);
if ($stmt->execute()) {
echo "success"; // Insert successful
} else {
echo "Error: " . $stmt->error; // Handle error
}
$stmt->close();
}
$conn->close();
?>