set_charset("utf8mb4");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
include '../project-photo-functions.php'; // Ensure this path is correct
$location_full = $_POST['location_address'] ?? 'Default Location';
$project_name = $_POST['project_name'];
$description_short = $_POST['description_short'];
$description_long = $_POST['description_long'];
$project_type = $_POST['project_type'];
$construction_type = $_POST['construction_type']; // keep this as it is
$community = $_POST['community'] ?? '';
$project_admins = $_POST['project_admins'] ?? '';
$start_dt = $_POST['start_dt'];
$briks_used = $_POST['briks_used'];
$est_avg_brik_weight = $_POST['est_avg_brik_weight'];
$latitude = (double)$_POST['latitude'];
$longitude = (double)$_POST['longitude'];
$connected_ecobricks = $_POST['connected_ecobricks'] ?? '';
$end_dt = $_POST['end_dt'];
$project_sort = $_POST['project_sort'] ?? '';
$sql = "INSERT INTO tb_projects (project_name, description_short, description_long, location_full, project_type, construction_type, community, project_admins, start_dt, briks_used, est_avg_brik_weight, location_lat, location_long, connected_ecobricks, end_dt, project_sort)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
if ($stmt = $conn->prepare($sql)) {
$stmt->bind_param("sssssssssiiddsss", $project_name, $description_short, $description_long, $location_full, $project_type, $construction_type, $community, $project_admins, $start_dt, $briks_used, $est_avg_brik_weight, $latitude, $longitude, $connected_ecobricks, $end_dt, $project_sort);
if ($stmt->execute()) {
$project_id = $conn->insert_id;
// Get the last inserted project_id
$project_id = $conn->insert_id;
// Calculate `est_total_weight`
$est_total_weight = ($briks_used * $est_avg_brik_weight) / 1000;
// Update `est_total_weight`
$update_weight_sql = "UPDATE tb_projects SET est_total_weight = ? WHERE project_id = ?";
$update_weight_stmt = $conn->prepare($update_weight_sql);
$update_weight_stmt->bind_param("di", $est_total_weight, $project_id);
$update_weight_stmt->execute();
$update_weight_stmt->close();
// Update `project_url`
$project_url = "https://ecobricks.org/en/project.php?id=" . $project_id;
$update_url_sql = "UPDATE tb_projects SET project_url = ? WHERE project_id = ?";
$update_url_stmt = $conn->prepare($update_url_sql);
$update_url_stmt->bind_param("si", $project_url, $project_id);
$update_url_stmt->execute();
$update_url_stmt->close();
$stmt->close();
$conn->close();
echo "";
} else {
echo "Error: " . $stmt->error . "
";
}
$stmt->close();
} else {
echo "Prepare failed: " . $conn->error;
}
$conn->close();
}
?>
Share your ecobrick project with the world. Use this form to post your completed ecobricks project onto ecobricks.org. Projects will be featured on our main page and archived in our database.