Example #1
0
<?php

// ini_set('display_errors', 'On');
// error_reporting(E_ALL);
include "./dic_map_func.php";
session_start();
$word = $_GET['word'];
$word = strtolower($word);
$command = $_GET['command'];
if ($command == "exist") {
    if (word_isExist($word)) {
        echo "true";
    } else {
        echo "false";
    }
} else {
    if ($command == "mean") {
        echo word_mean($word);
    } else {
        echo "No such command";
    }
}
Example #2
0
// get user name
$username = $username['name'];
if ($command == "get") {
    $query = mysql_query("SELECT `wordlist`, `mean`, `date` FROM wordbank WHERE username='******'");
    $ret = new StdClass();
    $result = mysql_fetch_array($query);
    $ret->wordlist = $result['wordlist'];
    $ret->mean = $result['mean'];
    $ret->date = $result['date'];
    echo json_encode($ret);
} else {
    if ($command == "add") {
        $words = $_POST['words'];
        // new words need to be added
        // $means = $_POST['means']; // queryed before
        $mean = word_mean($words[0]);
        $means[] = $mean;
        // Sorry, hard code for deadline ...
        $add_date = date('Y-m-d H:i:s');
        mysql_query("SET NAMES UTF8");
        $query = mysql_query("SELECT `wordlist`, `mean` FROM wordbank WHERE username='******'");
        if (mysql_num_rows($query) == 0) {
            // insert directly if user no bank
            $en_words = json_encode($words);
            $en_means = json_encode($means);
            mysql_query("INSERT INTO wordbank(`username`, `wordlist`, `mean`, `date`) VALUES ('{$username}', '{$en_words}', '{$en_means}', '{$add_date}')", $link);
        } else {
            // concat and unique if user had bank
            $result = mysql_fetch_array($query);
            $en_old_words = $result['wordlist'];
            $en_old_means = $result['mean'];