-
Notifications
You must be signed in to change notification settings - Fork 4
/
save_chat.php
37 lines (28 loc) · 1011 Bytes
/
save_chat.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
<?php
/**
* Created by PhpStorm.
* User: MokhtarKH
* Date: 04-05-2019
* Time: 9:30
*/
session_start();
include "init.php";
$user1=$_SESSION["username"];
$user2=$_SESSION["other_user"];
$id = $_SESSION["id"];
if(isset($_POST["send_message"])){
$_POST["txtmessage"]= trim($_POST["txtmessage"]);
if(!empty($_POST["txtmessage"])){
$sender=$_SESSION["username"];
$new_message= $_POST["txtmessage"];
if(strcmp($user1,$user2)>0)
{
$user2=$_SESSION["username"]; $user1=$_SESSION["other_user"];
};
$stmt = $conn->prepare("insert into messages (`user1`, `user2`, `sender`, `message`, `Time`, `lue`) values('$user1','$user2','$sender','$new_message',CURRENT_TIMESTAMP,0)");
$stmt->execute();
};
};
header("location:messages.php?target=" . $_SESSION["other_user"]);
exit();
?>