You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Code4Change/receiver.php

69 lines
2.1 KiB

6 months ago
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "foodshare";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$message = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $conn->real_escape_string($_POST['recipientName']);
$location = $conn->real_escape_string($_POST['recipientLocation']);
$foodNeeds = $conn->real_escape_string($_POST['foodNeeds']);
$sql = "INSERT INTO recipient (name, location, food_needs) VALUES ('$name', '$location', '$foodNeeds')";
if ($conn->query($sql) === TRUE) {
6 months ago
$message = "Your request has been matched. Food type: Vegetables , Pickup Location: Anamnagar ";
6 months ago
} else {
$message = "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Receiver</title>
<link rel="stylesheet" href="receiver.css">
<script>
// Display the message as a popup if it's set
function showMessage(message) {
if (message) {
alert(message);
}
}
</script>
</head>
<body onload="showMessage('<?= htmlspecialchars($message) ?>')">
<div class="container">
<img src="logo.png" alt="" class="logo">
<h2>Request Your Needs</h2>
<form method="POST" action="">
<label for="recipientName">Recipient Name</label>
<input type="text" id="recipientName" name="recipientName" placeholder="Enter organization name" required>
<label for="recipientLocation">Location</label>
<input type="text" id="recipientLocation" name="recipientLocation" placeholder="e.g., kathmandu" required>
<label for="foodNeeds">Food Needs</label>
<input type="text" id="foodNeeds" name="foodNeeds" placeholder="e.g., Any thing, Vegetables" required>
<button type="submit">Submit Needs</button>
</form>
</div>
</body>
</html>