/
CaseStudy2.php
67 lines (58 loc) · 1.52 KB
/
CaseStudy2.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
<?php
/**
* This section ensures that Twilio gets a response.
*/
header('Content-type: text/xml');
$from = $_REQUEST['From'];
$body = $_REQUEST['Body'];
$to = "+17049315308";
$caseStudy = "Case Study 2";
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<Response><Message>Thank you for your reply to '.$caseStudy.'</Message></Response>';
$conn = OpenConnection();
if(!empty($from)) {
InsertData($from, $body, $to, $caseStudy, $conn);
sqlsrv_close($conn);
}
else
{
sqlsrv_close($conn);
}
function OpenConnection()
{
try
{
$serverName = "tcp:j7luugiwb8.database.windows.net,1433";
$connectionOptions = array("Database"=>"Texting_APP",
"Uid"=>"arufolo@cardinalsolutions.com@j7luugiwb8", "PWD"=>"P@ssw0rd1");
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn == false)
die(FormatErrors(sqlsrv_errors()));
return $conn;
}
catch(Exception $e)
{
echo("Error!");
}
}
function InsertData($from, $body, $to, $caseStudy, $conn)
{
try
{
$tsql = "INSERT INTO TextQueue (PhoneNumber, TextContent, TextTo, CaseStudy) VALUES ('".$from."', '".$body."', '".$to."', '".$caseStudy."')";
$insertReview = sqlsrv_query($conn, $tsql);
if($insertReview == FALSE)
{
die(FormatErrors( sqlsrv_errors()));
}
while($row = sqlsrv_fetch_array($insertReview, SQLSRV_FETCH_ASSOC))
{
echo($row['ID']);
}
}
catch(Exception $e)
{
echo("Error!");
}
}
?>