-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendmsg.php
More file actions
54 lines (47 loc) · 1.15 KB
/
sendmsg.php
File metadata and controls
54 lines (47 loc) · 1.15 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
<?php
// Inialize session
session_start();
$con=mysqli_connect("localhost","root","r00t","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//echo $_SESSION['username'];
?>
<!DOCTYPE html>
<html>
<head>
<title>Sending Message</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="bootstrap/css/bootstrap.css" rel="stylesheet" media="screen">
</head>
</html>
<?php
$flag=0;
if ($_POST['msg']==NULL or $_POST['allusers']==NULL)
header('location:ComposeMsg.php');
foreach ($_POST['allusers'] as $value)
{
$sql="INSERT INTO messages (FromUser, ToUser, Message)
VALUES
('$_SESSION[username]','$value','$_POST[msg]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
$flag=1;
}
}
if ($flag!=1)
{?>
<html>
<div class="alert alert-block" >
<h4>Message Sent Successfully !!!
<a href="Main.php" class="btn btn-large pull-right" >Continue</a>
</h4>
<p>Your message has been successfully sent to all users.</p>
</div>
</html>
<?php
}
?>