Example #1
0
                echo json_encode($chat_rows);
            } else {
                if ($mode == "add") {
                    $student_name = $_GET['student_name'];
                    $dev_id = $_GET['devid'];
                    //change student's name
                    if ($student_name == "Anonymous") {
                        $sum = 0;
                        $strToEncode = substr($dev_id, -3);
                        for ($i = 0; $i < strlen($strToEncode); $i++) {
                            $sum += ord(substr($strToEncode, $i, 1));
                        }
                        $student_name = "usr" . $sum;
                    }
                    $text = $_GET['text'];
                    $sql = "INSERT INTO `chat` (`student_name`, `text`, `update_time`) VALUES ('{$student_name}', '{$text}', now())";
                    Database::execute($sql, $link);
                    if (mysql_affected_rows($link) > 0) {
                        $json['status'] = "success";
                        echo json_encode($json);
                    } else {
                        $json['status'] = "failed";
                        echo json_encode($json);
                    }
                }
            }
        }
    }
}
Database::close_database($link);