File: /var/www/vhosts/uat-api.tsprojects.net/httpdocs/ratemycoach-web/facProfileReadOnly.php
<?php
// Retrieve user ID from the URL
$user_id = $_GET["idUsers"];
// Connect to your MySQL database
$servername = "localhost";
$username = "pxhlcbmy_ccast99942cr";
$password = "rYCh2@23";
$dbname = "pxhlcbmy_coachrychdb";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM tblcoachesXL WHERE idUsers = $user_id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
} else {
$_SESSION['message'] = "User not found!";
header("Location: ../gptEditACoach.php");
exit;
}
// Check if the form has been submitted
$form_submitted = isset($_POST['submitBtn']);
// Handle form submission
if ($_SERVER["REQUEST_METHOD"] == "POST" && $form_submitted) {
$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$email = $_POST['email'];
$coachtitle = $_POST['coachtitle'];
$sports = $_POST['sports'];
$schoolname = $_POST['schoolname'];
$schoolcity = $_POST['schoolcity'];
$schoolstate = $_POST['schoolstate'];
$active = $_POST['active'];
$gender = $_POST['gender'];
$totalyearscoaching = $_POST['totalyearscoaching'];
$yearscoachinghere = $_POST['yearscoachinghere'];
$schoolwonlossrecord = $_POST['schoolwonlossrecord'];
$careerwonlossrecord = $_POST['careerwonlossrecord'];
$championships = $_POST['championships'];
$awards = $_POST['awards'];
// Update user data in the database
$update_sql = "UPDATE tblcoachesXL SET
f_name = '$f_name',
l_name = '$l_name',
emailUsers = '$email',
coachtitle = '$coachtitle',
sports = '$sports',
schoolname = '$schoolname',
schoolcity = '$schoolcity',
schoolstate = '$schoolstate',
gender = '$gender',
totalyearscoaching = '$totalyearscoaching',
yearscoachinghere = '$yearscoachinghere',
schoolwonlossrecord = '$schoolwonlossrecord',
careerwonlossrecord = '$careerwonlossrecord',
championships = '$championships',
awards = '$awards',
active = '$active'
WHERE idUsers = $user_id";
if ($conn->query($update_sql) === TRUE) {
$_SESSION['message'] = "Coach Profile updated successfully!";
} else {
$_SESSION['message'] = "Error updating profile data: " . $conn->error;
}
// Handle profile image upload only if a new image is selected
if ($_FILES["profile_image"]["name"] != "") {
$target_dir = "Profile4/uploads/";
$target_file = $target_dir . basename($_FILES["profile_image"]["name"]);
// Delete existing image (replace 'user_id' with the actual user ID)
$existing_image = "Profile4/uploads/" . $row['userImg']; // Fetch from database
if (file_exists($existing_image)) {
unlink($existing_image);
}
move_uploaded_file($_FILES["profile_image"]["tmp_name"], $target_file);
// Update the 'userImg' field in tblcoachesXL with the new image file name
$update_image_sql = "UPDATE tblcoachesXL SET userImg = '" . basename($_FILES["profile_image"]["name"]) . "' WHERE idUsers = $user_id";
if ($conn->query($update_image_sql) === TRUE) {
$_SESSION['message'] = "Profile image updated successfully!";
} else {
$_SESSION['message'] = "Error updating profile image: " . $conn->error;
}
}
// Redirect to the edit profile page after updating
header("Location: ../gptEditACoach.php?idUsers=$user_id");
exit;
}
// Close the database connection
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Coach RYCH - Rate Your Coach</title>
<meta charset="utf-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #652d90; /* Text color *;
}
h1 {
color: #642d90;
text-align: center;
font-size: 36px; /* Adjust the font size as needed */
margin-bottom: 20px; /* Add some margin below the title */
}
.form-container {
max-width:500px;
margin: 50px auto;
padding: 20px;
border: 1px solid #652D90;
border-radius: 5px;
background-color: #fff;
}
.form-row {
display: flex;
flex-direction: column;
margin-bottom: 15px;
}
.form-row label {
padding: 5px;
margin-bottom: 5px;
color: #652d90; /* Text color */
font-weight: bold; /* Make the text bold */
}
.form-row input[type="text"],
.form-row select {
padding: 8px;
border: 1px solid #652D90;
box-sizing: border-box;
}
#previewImage {
max-width: 40%;
height: auto;
margin-bottom: 15px;
}
.form-row .sports-field {
display: flex;
align-items: center;
border: 1px solid #652D90;
}
.form-row select {
flex: 1;
margin-left: 10px;
}
/* Submit button */
.form-row input[type="submit"] {
background-color: #652D90;
color: #fff;
height: 40px;
cursor: pointer;
}
.form-row input[type="submit"]:enabled {
background-color: green;
}
</style>
</head>
<body>
<div class="form-container">
<center><h1>COACH PROFILE</h1></center>
<!-- Display session messages -->
<?php if (isset($_SESSION['message'])): ?>
<center> <?php echo $_SESSION['message']; ?></center>
<center><?php unset($_SESSION['message']); ?></center>
<?php endif; ?>
<form id="profileForm" action="<?php echo $_SERVER['PHP_SELF'].'?idUsers='.$user_id; ?>" method="post" enctype="multipart/form-data">
<!-- Display existing profile image -->
<center><img src="Profile4/uploads/<?php echo $row['userImg']; ?>" alt="Profile Image" id="previewImage" /></center>
<div class="form-row">
<label for="f_name">First Name:</label>
<input type="text" name="f_name" id="f_name" value="<?php echo $row['f_name']; ?>" readonly>
</div>
<div class="form-row">
<label for="l_name">Last Name:</label>
<input type="text" name="l_name" id="l_name" value="<?php echo $row['l_name']; ?>" readonly>
</div>
<div class="form-row">
<label for="email">Email:</label>
<input type="text" name="email" id="email" value="<?php echo $row['emailUsers']; ?>" readonly>
</div>
<div class="form-row">
<label for="coachtitle">Coach Title:</label>
<input type="text" name="coachtitle" id="coachtitle" value="<?php echo $row['coachtitle']; ?>" readonly>
</div>
<div class="form-row">
<label for="gender">Gender:</label>
<input type="text" name="gender" id="gender" value="<?php echo $row['gender']; ?>" readonly>
</div>
<div class="form-row sports-field">
<label for="sports">Sports:</label>
<input type="text" name="sports" id="sports" value="<?php echo $row['sports']; ?>" readonly>
</div>
<div class="form-row">
<label for="schoolname">School Name:</label>
<input type="text" name="schoolname" id="schoolname" value="<?php echo $row['schoolname']; ?>" readonly>
</div>
<div class="form-row">
<label for="schoolcity">School City:</label>
<input type="text" name="schoolcity" id="schoolcity" value="<?php echo $row['schoolcity']; ?>" readonly>
</div>
<div class="form-row">
<label for="schoolstate">School State:</label>
<input type="text" name="schoolstate" id="schoolstate" value="<?php echo $row['schoolstate']; ?>" readonly>
</div>
<div class="form-row">
<label for="totalyearscoaching">Total Years Coaching:</label>
<input type="text" name="totalyearscoaching" id="totalyearscoaching" value="<?php echo $row['totalyearscoaching']; ?>" readonly>
</div>
<div class="form-row">
<label for="yearscoachinghere">Years Coaching Here:</label>
<input type="text" name="yearscoachinghere" id="yearscoachinghere" value="<?php echo $row['yearscoachinghere']; ?>" readonly>
</div>
<div class="form-row">
<label for="schoolwonlossrecord">School Won/Loss Record:</label>
<input type="text" name="schoolwonlossrecord" id="schoolwonlossrecord" value="<?php echo $row['schoolwonlossrecord']; ?>" readonly>
</div>
<div class="form-row">
<label for="careerwonlossrecord">Career Won/Loss Record:</label>
<input type="text" name="careerwonlossrecord" id="careerwonlossrecord" value="<?php echo $row['careerwonlossrecord']; ?>" readonly>
</div>
<div class="form-row">
<label for="championships">Championships:</label>
<textarea maxlength="250" rows="6" cols="60" wrap="hard" name="championships" id="championships"> <?php echo $row['championships']; ?></textarea>
</div>
<div class="form-row">
<label for="awards">Awards:</label>
<textarea maxlength="250" rows="6" cols="60" wrap="hard" name="awards" id="awards"> <?php echo $row['awards']; ?></textarea>
</div>
<!-- Submit button -->
<div class="form-row">
<a href='coachcorner/search.php'>
<button >
Go Back
</button>
</a>
</div>
</form>
</div>
</body>
</body>
</html>