-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinsert_ticket_contact.php
89 lines (65 loc) · 1.8 KB
/
insert_ticket_contact.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
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//require DB
require ("db_config.php");
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR
die('Coul not connect MySQL: ' . mysqli_connect_error () );
//set encoding
mysqli_set_charset($dbc, 'utf8');
$output = '';
$query = "insert into customers (email";
$values = "(";
if (isset ($_POST['email'])){
$email = mysqli_real_escape_string($dbc, $_POST["email"]);
$values = $values . " '$email' ";
}
if (!empty($_POST['name'])){
$name = mysqli_real_escape_string($dbc, $_POST["name"]);
$query = $query . ",name";
$values = $values . ", '$name' ";
}
$values = $values . ")";
$query = $query . ") values" . $values;
if (mysqli_query($dbc, $query)){
$last_id = mysqli_insert_id($dbc);
}
else{
// echo "there was a problem insertin the users";
die();
}
$query = "insert into tickets (customer";
$values = "(".$last_id ;
if (!empty($_POST['subject'])){
$subject = mysqli_real_escape_string($dbc, $_POST["subject"]);
$query = $query . ",subject";
$values = $values . ", '$subject' ";
}
if (!empty($_POST['status'])){
$status = mysqli_real_escape_string($dbc, $_POST["status"]);
$query = $query . ",status";
$values = $values . ", '$status' ";
}
else {
$status = 'New';
$query = $query . ",status";
$values = $values . ", '$status' ";
}
if (!empty ($_POST['description'])){
$description = mysqli_real_escape_string($dbc, $_POST["description"]);
$query = $query . ",description";
$values = $values . ", '$description' ";
}
$values = $values . ")";
$query = $query . ") values" . $values;
echo $query;
if (mysqli_query($dbc, $query)){
// echo "tickets succesfully created";
}
else {
// echo "ticket wasnt created";
}
}
else{
// echo "Someting happened here";
}
?>