protected function init() { session_start(); if (empty($_SESSION['user_info']) || empty($_POST['content'])) { echo 'error'; exit; } else { $content = $_POST['content']; $id = $_POST['id']; $name = $_SESSION['user_info']['nickname']; $header = $_SESSION['user_info']['header']; if (empty($header)) { $header = 'http://7xngw8.com1.z0.glb.clouddn.com/title.png'; //默认头像 } $local_db = new lhh_db(); //检验是不是重复参与的,并计入参与人数 $num = $local_db->count('dbd_comment', '*', array('AND' => array('u_name' => $name, 'dbd_id' => $id))); if (empty($num)) { $local_db->update('dbd_list', array('count[+]' => 1), array('id' => $id)); } date_default_timezone_set('PRC'); $re = $local_db->insert('dbd_comment', array('u_name' => $name, 'header' => $header, 'dbd_id' => $id, 'content' => $content, 'time' => time(), 'up' => 0)); if ($re > 0) { echo 'ok'; } else { echo 'fail'; } } }
protected function init() { date_default_timezone_set('PRC'); $local_db = new lhh_db(); $re = $local_db->insert('lhh_comment', array('u_name' => $_POST['name'], 'lhh_id' => $_POST['id'], 'time' => time(), 'content' => $_POST['text'])); if (!empty($re)) { echo 'ok'; } else { echo 'error'; } }
protected function insert_into_database($auth, $type, $append, $content) { $local_db = new lhh_db(); // print_r($local_db); date_default_timezone_set('PRC'); $re = $local_db->insert('lhh_list', array('header' => 'http://7xnquu.com1.z0.glb.clouddn.com/app_icon.png', 'auth' => $auth, 'type' => $type, 'append' => $append, 'content' => $content, 'time' => time(), 'up' => 0, 'down' => 0, 'comment' => 0)); if (!empty($re)) { echo '上传成功!'; } else { echo '上传失败!'; } }
<?php /** * Created by PhpStorm. * User: KeenSting * Date: 2015/11/24 * Time: 20:47 */ require 'medoo.php'; $id = $_POST['id']; session_start(); if (empty($_SESSION['user_info']) || empty($_POST)) { echo 'error'; exit; } $db = new lhh_db(); $num = $db->count('dbd_record', '*', array('AND' => array('comment_id' => $id, 'uid' => $_SESSION['user_info']['uid']))); if (empty($num)) { $db->update('dbd_comment', array('up[+]' => 1), array('id' => $id)); $db->insert('dbd_record', array('comment_id' => $id, 'uid' => $_SESSION['user_info']['uid'])); echo 'ok'; } else { echo 'repeat'; }