-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_vote.php
More file actions
34 lines (28 loc) · 984 Bytes
/
Copy pathprocess_vote.php
File metadata and controls
34 lines (28 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
// Database configuration
$db_host = 'node6482-expo-demo.fin.libyanspider.cloud';
$db_user = 'root';
$db_password = 'FGSxgo42839';
$db_name = 'election';
// Connect to the database
try {
$pdo = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_password);
// Set PDO to throw exceptions on error
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Connection failed: " . $e->getMessage());
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$voter_name = $_POST['voter_name'];
$candidate = $_POST['candidate'];
try {
$sql = "INSERT INTO votes (voter_name, candidate) VALUES (?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$voter_name, $candidate]);
echo "Vote recorded successfully!";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
// Close the database connection (PDO does this automatically when the script ends).
?>