-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplants_tortured.php
47 lines (37 loc) · 1.34 KB
/
plants_tortured.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
<?php
/*
* Every time the torture screen is closed, this script is executed. It simply increases the number of plants tortured
* by 1.
*/
// Start the session
session_start();
// Connect to the database
include('db_connect.php');
// Get the number of plants tortured. Prepare the statement to prevent sql injection
if ($stmt = $connect->prepare('SELECT plants_tortured FROM User WHERE user_id = ?')) {
// Replace the questionmark with the user id (i := integer)
$stmt->bind_param('i', $_SESSION['user_id']);
// Execute the query above
$stmt->execute();
// Stores the result in the variable $plants_tortured
$stmt->store_result();
$stmt->bind_result($plants_tortured);
$stmt->fetch();
// Close the statement
$stmt->close();
} else{
die('Couldn\'t get the number of plants tortured.');
}
// Increment the amount of plants tortured. To be sure convert the variable to an integer
$plants_tortured = intval($plants_tortured) + 1;
// Update the new number
if($stmt = $connect->prepare("UPDATE User SET plants_tortured = ? WHERE user_id = ? ")){
$stmt->bind_param('ii', $plants_tortured, $_SESSION['user_id']);
$stmt->execute();
} else{
die('An error occured when updating the number of plants tortured.');
}
$stmt->close();
// Close the connection to the database
$connect->close();
?>