-
Notifications
You must be signed in to change notification settings - Fork 1
/
sendmessage.php
70 lines (58 loc) · 1.78 KB
/
sendmessage.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
<?php
session_start();
$name = $_SESSION['user'];
$sendname = $_SESSION['tomsgs'];
// echo $name;
// echo $sendname;
if(isset($_POST['send'])) {
define('MyConst', TRUE);
}
if(!defined('MyConst')) {
echo '<script language="javascript">';
echo 'alert("Access Denied");';
echo '</script>';
header("Refresh: 1; url=welcome.php");
}
else {
if(!empty($_POST['tomsg']) && !empty($_POST['msgbody'])) {
$tomsg = htmlentities($_POST['tomsg']);
$msgbody = htmlentities($_POST['msgbody']);
}
else {
echo '<script language="javascript">';
echo 'alert("Enter All the Details first !");';
echo '</script>';
header("Location:message.php");
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pdologin";
$tbname = "messages";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = $conn->prepare("INSERT INTO $tbname (tomsg,frommsg,msgbody) VALUES (:tomsg,:frommsg,:msgbody)");
$do = $sql->execute(['tomsg' => $sendname, 'frommsg' => $name, 'msgbody' => $msgbody]);
if($do) {
echo '<script language="javascript">';
echo 'alert("Message Sent Successfully !");';
echo '</script>';
header("Location:sent.php");
}
else {
echo '<script language="javascript">';
echo 'alert("Looks like there is some Error !");';
echo '</script>';
header("Refresh: 1; url=welcome.php");
}
}
catch(PDOException $e) {
echo '<script language="javascript">';
echo '$sql . "<br>" . $e->getMessage();';
echo '</script>';
header("Refresh: 1; url=welcome.php");
}
$conn = NULL;
}
?>