jsut a little naming change in the db

main
Grim0o5 6 months ago
parent 68f89bb42d
commit e874ec2b72
  1. 24
      employerprofile.php
  2. 17
      updateemployeeprofile.php

@ -13,9 +13,8 @@ if (!isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id']; // Get user ID from the session $user_id = $_SESSION['user_id']; // Get user ID from the session
// Fetch user data from the database // Fetch user data from the database
$query = "SELECT u.firstname, u.lastname, u.email, u.phone, $query = "SELECT u.firstname, u.lastname,u.username, u.email, u.phone,
e.company_name, e.company_email, e.company_address, e.address
e.industry
FROM users u FROM users u
LEFT JOIN employers e ON u.user_id = e.user_id LEFT JOIN employers e ON u.user_id = e.user_id
WHERE u.user_id = ?"; WHERE u.user_id = ?";
@ -96,6 +95,19 @@ if ($result->num_rows > 0) {
required required
> >
</div> </div>
<!-- Username -->
<div class="form-control">
<label class="label">
<span class="label-text">Username</span>
</label>
<input
type="text"
name="username"
value="<?php echo isset($user['username']) ? $user['username'] : ''; ?>"
class="input input-bordered w-full"
required
>
</div>
<!-- Phone Number --> <!-- Phone Number -->
<div class="form-control"> <div class="form-control">
@ -114,12 +126,12 @@ if ($result->num_rows > 0) {
<!-- Company Address --> <!-- Company Address -->
<div class="form-control"> <div class="form-control">
<label class="label"> <label class="label">
<span class="label-text">Company Address</span> <span class="label-text"> Address</span>
</label> </label>
<input <input
type="text" type="text"
name="company_address" name="address"
value="<?php echo isset($user['company_address']) ? $user['company_address'] : ''; ?>" value="<?php echo isset($user['address']) ? $user['address'] : ''; ?>"
class="input input-bordered w-full" class="input input-bordered w-full"
required required
> >

@ -15,7 +15,8 @@ if (isset($_POST['update'])) {
$last_name = trim($_POST['last_name']); $last_name = trim($_POST['last_name']);
$email = trim($_POST['email']); $email = trim($_POST['email']);
$phone = trim($_POST['phone']); $phone = trim($_POST['phone']);
$company_address = trim($_POST['company_address']); $username = trim($_POST['username']);
$address = trim($_POST['address']);
try { try {
@ -23,13 +24,13 @@ if (isset($_POST['update'])) {
// 1. First update the users table // 1. First update the users table
$query_users = "UPDATE users $query_users = "UPDATE users
SET firstname = ?, lastname = ?, email = ?, phone = ? SET firstname = ?, lastname = ?, email = ?, phone = ? ,username =?
WHERE user_id = ?"; WHERE user_id = ?";
$stmt_users = $conn->prepare($query_users); $stmt_users = $conn->prepare($query_users);
if (!$stmt_users) { if (!$stmt_users) {
throw new Exception("Prepare failed for users table: " . $conn->error); throw new Exception("Prepare failed for users table: " . $conn->error);
} }
$stmt_users->bind_param("ssssi", $first_name, $last_name, $email, $phone, $user_id); $stmt_users->bind_param("sssssi", $first_name, $last_name, $email, $phone, $username,$user_id);
if (!$stmt_users->execute()) { if (!$stmt_users->execute()) {
throw new Exception("Error updating users table: " . $stmt_users->error); throw new Exception("Error updating users table: " . $stmt_users->error);
@ -48,29 +49,29 @@ if (isset($_POST['update'])) {
// Update existing record // Update existing record
$employer_query = "UPDATE employers $employer_query = "UPDATE employers
SET SET
company_address = ? address = ?
WHERE user_id = ?"; WHERE user_id = ?";
} else { } else {
// Insert new record // Insert new record
$employer_query = "INSERT INTO employers $employer_query = "INSERT INTO employers
( company_address, user_id) ( address, user_id)
VALUES (?, ?)"; VALUES (?, ?)";
} }
$stmt_employers = $conn->prepare($employer_query); $stmt_employers = $conn->prepare($employer_query);
if (!$stmt_employers) { if (!$stmt_employers) {
throw new Exception("Prepare failed for job_seekers table: " . $conn->error); throw new Exception("Prepare failed for Employer table: " . $conn->error);
} }
// Same binding for both UPDATE and INSERT // Same binding for both UPDATE and INSERT
$stmt_employers->bind_param("si", $stmt_employers->bind_param("si",
$company_address, $address,
$user_id $user_id
); );
if (!$stmt_employers->execute()) { if (!$stmt_employers->execute()) {
throw new Exception("Error with job_seekers table: " . $stmt_employers->error); throw new Exception("Error with E ployers table: " . $stmt_employers->error);
} }
$conn->commit(); $conn->commit();

Loading…
Cancel
Save