-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.php
More file actions
73 lines (63 loc) · 2.3 KB
/
Copy pathserver.php
File metadata and controls
73 lines (63 loc) · 2.3 KB
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
<?php
function sendFailure($msg) {
$output = array(
'success' => false,
'status' => $msg
);
echo(json_encode($output));
}
function sendSuccess($msg) {
$output = array(
'success' => true,
'status' => $msg
);
echo(json_encode($output));
}
function generate_string($input, $strength = 16)
{
$input_length = strlen($input);
$random_string = '';
for($i = 0; $i < $strength; $i++) {
$random_character = $input[mt_rand(0, $input_length - 1)];
$random_string .= $random_character;
}
return $random_string;
}
if(!isset($_POST)) sendFailure("No values received");
else {
try {
$name = empty($_POST['name']) ? '' : $_POST['name'];
$insti = empty($_POST['insti']) ? '' : $_POST['insti'];
$stream = empty($_POST['stream']) ? '' : $_POST['stream'];
$course = empty($_POST['cor']) ? '' : $_POST['cor'];
$year = empty($_POST['year']) ? '' : $_POST['year'];
$phno = empty($_POST['phno']) ? '' : $_POST['phno'];
$email = empty($_POST['email']) ? '' : $_POST['email'];
$event = empty($_POST['events']) ? '' : $_POST['events'];
$teamsize = empty($_POST['teamsize']) ? '' : $_POST['teamsize'];
$teammember = empty($_POST['teammember']) ? '' : $_POST['teammember'];
$servername = "localhost";
$username = "id7542107_root";
$password = "user123";
$dbname = "id7542107_registrations";
$permitted_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$str = generate_string($permitted_chars,20);
$stmt = $conn->prepare("INSERT INTO registrations (regno,regname,institution,stream,course,year,moblie,email,event,teamsize, teammembers) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssiissis",$str,$name,$insti,$stream,$course,$year,$phno,$email,$event,$teamsize,$teammember);
if($stmt->execute()) {
sendSuccess("New entry recorded");
} else {
sendFailure("New entry could not be recorded");
}
$stmt->close();
$conn->close();
} catch(Exception $e) {
sendFailure("Could not be recorded");
}
}
?>