-
Notifications
You must be signed in to change notification settings - Fork 0
/
otziv_send.php
49 lines (40 loc) · 946 Bytes
/
otziv_send.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
<?php
include_once 'config.php';
$name=substr($_POST['userName'], 0, 55);
$msg=$_POST['userMsg'];
//echo $name;
//Очистка данных.
function clearData($var){
$var = trim(mysql_real_escape_string($var));
return $var;
}
//Отправка сообщения.
function add_post($name,$msg){
$name = clearData($name);
$msg = clearData($msg);
if(empty($name)) $name = 'Гость';
if(!empty($msg)){
$query = "INSERT INTO msg (username, post)
VALUES ('$name','$msg')";
if(mysql_query($query)){
$res = 0;
}
else{
$res = 1;
}
}
return $res;
}
$send = add_post($name,$msg);
if($send!=0){
echo 'Произошла ошибка, попробуйте ещё раз';
}
else{
$last_id = mysql_insert_id();
$query = "SELECT username, post, LEFT(date, 16) AS date FROM msg WHERE id = $last_id";
$res = mysql_query($query);
$arr_res = mysql_fetch_assoc($res);
echo json_encode($arr_res);
}
mysql_close();
?>