connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Ensure user is logged in before accessing user_id
if (isset($_SESSION['user_id'])) {
$userId = $_SESSION['user_id']; // Get user_id from session
$title = $_POST['title'];
$story = $_POST['story'];
$industry = $_POST['industry'];
$role = $_POST['role'];
// Handle file upload
$targetDir = "uploads/"; // Directory where images will be uploaded
$targetFile = $targetDir . basename($_FILES["image"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["image"]["tmp_name"]);
if ($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
// Check file size (optional)
if ($_FILES["image"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
if (move_uploaded_file($_FILES["image"]["tmp_name"], $targetFile)) {
echo "The file " . htmlspecialchars(basename($_FILES["image"]["name"])) . " has been uploaded.";
// Insert story into database
$sql = "INSERT INTO success_stories (user_id, title, story, industry, role, image, created_at) VALUES ('$userId', '$title', '$story', '$industry', '$role', '$targetFile', NOW())";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "
" . $conn->error;
}
} else {
echo "Sorry, there was an error uploading your file.";
}
}
} else {
echo "You must be logged in to submit a story.";
}
}
// Fetch the featured story
$featuredStory = null; // Initialize the variable
$sqlFeatured = "SELECT s.title, s.story, u.username FROM success_stories s JOIN users u ON s.user_id = u.id ORDER BY s.created_at DESC LIMIT 1"; // Modify query as needed
$resultFeatured = $conn->query($sqlFeatured);
if ($resultFeatured->num_rows > 0) {
$featuredStory = $resultFeatured->fetch_assoc(); // Get the first row as the featured story
}
?>
By:
Women Empowered
Featured Success Stories
Programs Offered