-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendMessage.php
More file actions
40 lines (33 loc) · 974 Bytes
/
Copy pathsendMessage.php
File metadata and controls
40 lines (33 loc) · 974 Bytes
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
<?php
$host = "localhost";
$user = "first_year";
$database = "first_year";
$passwd = "first_year";
$con = mysqli_connect($host, $user, $passwd, $database);
if(!$con) {
die("Can not connect: ".mysqli_connect_error());
}
$table = "mihir_messages";
$sent_by = $_POST['sent_by'];
$sent_to = $_POST['sent_to'];
$message = $_POST['message'];
if(empty($message)) {
echo "<script>alert('Empty message.');</script>";
}
else if(empty($sent_by) || empty($sent_to)) {
echo "<script>alert('Empty sent_by or sent_to');</script>";
}
else {
$sql = "INSERT INTO $table (sent_by, sent_to, message) VALUES (?, ?, ?)";
$stmt = mysqli_stmt_init($con);
if(!mysqli_stmt_prepare($stmt, $sql)) {
echo "<script>alert('SQL Error');</script>";
}
else {
mysqli_stmt_bind_param($stmt, "sss", $sent_by, $sent_to, $message);
mysqli_stmt_execute($stmt);
}
}
mysqli_stmt_close($stmt);
mysqli_close($con);
?>