-
Notifications
You must be signed in to change notification settings - Fork 1
/
electricityform_connection.php
71 lines (60 loc) · 2.74 KB
/
electricityform_connection.php
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$database = "ecotrack";
$conn = mysqli_connect($servername, $username, $password, $database);
if (!$conn) {
die("Sorry!! Failed to connect: " . mysqli_connect_error());
} else {
echo "Connection was successful<br>";
}
if (isset($_SESSION['uname'])) {
$uname = $_SESSION['uname'];
$fetch_email_sql = "SELECT email FROM newuser_credentials WHERE uname = ?";
$stmt = $conn->prepare($fetch_email_sql);
$stmt->bind_param("s", $uname);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$email = $row['email'];
$_SESSION['email'] = $email;
}
if (isset($_POST['Submit'])) {
$persons = $_POST['persons'];
$energy_efficient_appliances = $_POST['energy_efficient_appliances'];
$heating_cooling = $_POST['heating_cooling'];
$laundry_frequency = $_POST['laundry_frequency'];
$turn_off_lights = $_POST['turn_off_lights'];
$lighting_type = $_POST['lighting_type'];
$solar_panels = $_POST['solar_panels'];
$unplug_electronics = $_POST['unplug_electronics'];
$units_consumped = $_POST['units_consumped'];
$device_name = $_POST['device_name'];
$quantity = $_POST['quantity'];
$duration = $_POST['duration'];
$device_name2 = $_POST['device_name2'];
$quantity2 = $_POST['quantity2'];
$duration2 = $_POST['duration2'];
$device_name3 = $_POST['device_name3'];
$quantity3 = $_POST['quantity3'];
$duration3 = $_POST['duration3'];
if (!isset($_SESSION['email']) || empty($_SESSION['email'])) {
echo "Email is missing!";
exit;
}
$email = $_SESSION['email'];
$sql = "INSERT INTO user_electricityform_credentials (email, persons, energy_efficient_appliances, heating_cooling, laundry_frequency, turn_off_lights, lighting_type, solar_panels, unplug_electronics, units_consumped, device_name, quantity, duration, device_name2, quantity2, duration2, device_name3, quantity3, duration3)
VALUES ('$email', '$persons', '$energy_efficient_appliances', '$heating_cooling', '$laundry_frequency', '$turn_off_lights', '$lighting_type', '$solar_panels', '$unplug_electronics', '$units_consumped', '$device_name', '$quantity', '$duration', '$device_name2', '$quantity2', '$duration2', '$device_name3', '$quantity3', '$duration3')";
$result = mysqli_query($conn, $sql);
if ($result) {
echo "<script>
alert('Form data submitted successfully')
window.location.href='dashboard.php'
</script>";
} else {
echo '<script>alert("Some internal error occurred..Try again")</script>';
}
}
?>