Untitled

 avatar
unknown
plain_text
a month ago
959 B
3
Indexable
public static function register($data) {
    global $pdo;

    // Check if email already exists
    $stmt = $pdo->prepare("SELECT * FROM students WHERE email = ?");
    $stmt->execute([$data['email']]);
    if ($stmt->rowCount() > 0) {
        return ['status' => 'error', 'message' => 'Email already exists.'];
    }

    // Hash the password
    $hashedPassword = md5($data['password']);

    // FIXED: Add column list before VALUES
    $sql = "INSERT INTO students 
            (first_name, last_name, birthdate, email, password, contact, address, gender) 
            VALUES (?, ?, ?, ?, ?, ?, ?, ?)";

    $stmt = $pdo->prepare($sql);

    $stmt->execute([
        $data['first_name'],
        $data['last_name'],
        $data['birthdate'],
        $data['email'],
        $hashedPassword,
        $data['contact'],
        $data['address'],
        $data['gender']
    ]);

    return ['status' => 'success', 'message' => 'Registration successful.'];
}
Editor is loading...
Leave a Comment