-
Notifications
You must be signed in to change notification settings - Fork 8
/
save_event_table.php
51 lines (47 loc) · 1.51 KB
/
save_event_table.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
<?php
include 'apiLe/dbConfig.php';
session_start();
function SQLInjFilter(&$unfilteredString){
$unfilteredString = mb_convert_encoding($unfilteredString, 'UTF-8', 'UTF-8');
$unfilteredString = htmlentities($unfilteredString, ENT_QUOTES, 'UTF-8');
// return $unfilteredString;
}
$directory = 'eventdata';
if (!is_dir($directory)) {
echo "Could not find events.";
}else{
$event_id = array();
foreach(scandir($directory) as $file) {
if('.' === $file) continue;
if('..' === $file) continue;
array_push($event_id, explode('.', $file)[0]);
}
if($link =mysqli_connect($servername, $username, $password, $dbname)){
foreach($event_id as $value) {
if($str = file_get_contents("eventdata/". $value . ".json")){
$event_data = json_decode($str, true);
$ok = 1;
$event_name = $event_data['name'];
$catagory_name = $event_data['catagory'];
SQLInjFilter($value);
SQLInjFilter($event_name);
SQLInjFilter($catagory_name);
$sql = "INSERT INTO `events` VALUES ('".$value."', '".$event_name."', '".$catagory_name."')";
$result = mysqli_query($link,$sql);
if($result){
echo "\ndone -> ".$value;
//successfully entered.
}else{
if(mysqli_errno($link)==1062){
echo "\n You are already registered to this event.->".$value;
}else{
echo "\n could not enter->".$value;
}
}
}
}
}else{
echo "Could not connect to database.";
}
}
?>