-
Notifications
You must be signed in to change notification settings - Fork 0
/
qSimpleSending.php
104 lines (86 loc) · 2.43 KB
/
qSimpleSending.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
function getIP()
{
$ip = $_SERVER['SERVER_ADDR'];
if (PHP_OS == 'WINNT')
{
$ip = getHostByName(getHostName());
}
if (PHP_OS == 'Linux')
{
$command = "/sbin/ifconfig";
exec($command, $output);
// var_dump($output);
$pattern = '/inet addr:?([^ ]+)/';
$ip = array();
foreach($output as $key => $subject)
{
$result = preg_match_all($pattern, $subject, $subpattern);
if ($result == 1)
{
if ($subpattern[1][0] != "127.0.0.1") $ip = $subpattern[1][0];
}
}
}
return $ip;
}
$ClientiP = getIP();
$server = "localhost";
$date = date('Y-m-d H:i:s');
$options = array(
"UID" => "root",
"PWD" => "password29",
"DB" => "questionnaire"
);
echo "<p>Trying to access the database...</p>";
$conn = mysqli_connect($server, "root", "password29", "questionnaire");
if (!$conn) die("<pre>" . print_r(mysqli_connect_error() , true));
echo "<p>Connection established.</p>";
$sql = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'questionnaire' AND table_name = 'testdatabase'";
$query = mysqli_query($conn, $sql);
$assoc = mysqli_fetch_assoc($query);
$numberColumns = $assoc['COUNT(*)'];
$sql = "SELECT * FROM testdatabase";
$query = mysqli_query($conn, $sql);
if (!$query)
{
exit("<pre>" . print_r(mysqli_error($query) , true));
}
array_unshift($_POST, $date);
array_unshift($_POST, $ClientiP);
$sql = "INSERT INTO testdatabase VALUES (";
$last_key = end(array_keys($_POST));
foreach($_POST as $key => $element)
{
if ($key == '0')
{
//$key = 'general_ip';
$sql = $sql . "'" . $element . "',";
}
elseif ($key == '1')
{
//$key = 'general_date';
$sql = $sql . "'" . $element . "',";
}
elseif ($key == $last_key)
{
$sql = $sql . "'" . $element . "',NULL)";
}
else
{
$sql = $sql . "'" . $element . "',";
}
}
echo $sql;
$query = mysqli_query($conn, $sql);
if (!$query)
{
exit("<pre>" . print_r(mysqli_error($query) , true));
}
else
{
echo "<p>Results of the questionnaire added successfully to the database.</p>";
}
mysqli_close($conn);
echo "<p>Connection closed.</p>";
?>