老大 ,获取时间和IP为0

#1 gw2010

这是 源码
 
function getDateTime()
{
  date_default_timezone_set("Asia/Chongqing");
  return date($date,"Y-m-d H:i:s");
}
function write(){ // 这里是留言
  $topic = spClass("topic");
  $newrow = array( // 这里制作新增记录的值
   'name' => $this->spArgs('name'),
   'title' => $this->spArgs('title'), // 从spArgs获取到表单提交上来的title
   'email' => $this->spArgs('email'),
   'contents' => $this->spArgs('contents'),
   'url' => $this->spArgs('url'),
   $ip => $this->getIP('ip'),
   $date => $this->getDateTime('date'),   
  );
  $topic->create($newrow);
  echo "发表成功,点击返回";
}
function getIP()
{
  if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
  {
        if ($_SERVER["HTTP_CLIENT_IP"])
        {
             $proxy = $_SERVER["HTTP_CLIENT_IP"];
        }
        else
        {
             $proxy = $_SERVER["REMOTE_ADDR"];
        }
       $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  }
  else
  {
       if (isset($_SERVER["HTTP_CLIENT_IP"]))
       {
             $ip = $_SERVER["HTTP_CLIENT_IP"];
        }
        else
        {
             $ip = $_SERVER["REMOTE_ADDR"];
        }
  }
  return $ip;
}


获取了时间和 IP后,直接 导入数据库,还是 返回 smarty和 表单一起导入 ,请教一下怎么写。

我纯粹菜鸟。
谢谢

2011-08-10 09:47:30

#2 jake

不清楚你说的导入是什么,上面的代码,主要的问题在下面红色两点
$newrow = array( // 这里制作新增记录的值
   'name' => $this->spArgs('name'),
   'title' => $this->spArgs('title'), // 从spArgs获取到表单提交上来的title
   'email' => $this->spArgs('email'),
   'contents' => $this->spArgs('contents'),
   'url' => $this->spArgs('url'),
   $ip => $this->getIP('ip'),
   $date => $this->getDateTime('date'),   
  );

改回数据库中的IP和时间的字段名就可以了。比如说IP在数据库中叫ip,时间叫 mytime
$newrow = array( // 这里制作新增记录的值
   'name' => $this->spArgs('name'),
   'title' => $this->spArgs('title'), // 从spArgs获取到表单提交上来的title
   'email' => $this->spArgs('email'),
   'contents' => $this->spArgs('contents'),
   'url' => $this->spArgs('url'),
   'ip' => $this->getIP('ip'),
   'mytime'=> $this->getDateTime('date'),   
  );

2011-08-10 09:55:47

#3 Pony

什么意思,没弄明白
  return date($date,"Y-m-d H:i:s"); //这行是错误的 return date("Y-m-d H:i:s");

$ip => $this->getIP('ip'),//这行也是错误的 $ip => $this->getIP(),
$date => $this->getDateTime('date'), // $date => $this->getDateTime(),

2011-08-10 12:12:26

#4 jake

或许是不了解 $ 的使用吧

2011-08-10 13:31:39

#5 gw2010

已经明白了 ,检测放在 model就对了

2011-08-10 21:52:50