function addVote($pUserId,$pVisteIp,$pVoteTime)
{
if(!checkVote($pUserId,$pVisteIp,$pVoteTime))
return false;
$sql="insert into vote set user_id='$pUserId',vister_ip='$pVisteIp',vote_time='$pVoteTime'";
$this->mDB->query($sql);
$this->mDB->getInsertId ();
return ture;
}
这样试试
{
if(!checkVote($pUserId,$pVisteIp,$pVoteTime))
return false;
$sql="insert into vote set user_id='$pUserId',vister_ip='$pVisteIp',vote_time='$pVoteTime'";
$this->mDB->query($sql);
$this->mDB->getInsertId ();
return ture;
}
这样试试
错了
return true;
$this->mDB = new mysql;
// class.mysql.php
//
// class MySQL
{
var $mDBId;
var $mLink; function MySQL ($i = "0")
{
$this->mDBId = $i;
$this->mLink = -1;
} function getLink ()
{
if (-1 == $this->mLink || !$this->mLink)
{
global $array_db;
$this->mLink = mysql_connect ("cndb", "temp", "temp");
mysql_select_db ("temp", $this->mLink);
} return true;
}
function query ($pSql)
{
$this->getLink ();
return mysql_query ($pSql, $this->mLink);
}
function fetchArray ($pResult)
{
return mysql_fetch_array ($pResult);
}
function getInsertId ()
{
if (-1 == $this->mLink)
return false;
else
return mysql_insert_id ($this->mLink);
}
function getNumRows ($pResult)
{
return mysql_num_rows($pResult);
}
}
?>
只有当表vote中没有记录时,addvote()才会执行,怎么回事?
但是在插入时是错误的格式,建议
$sql="insert into vote set user_id='$pUserId',vister_ip='$pVisteIp',vote_time=NOW()";
{
if(checkVote($pUserId,$pVisteIp,$pVoteTime))
{
$sql="insert into vote set user_id='$pUserId',vister_ip='$pVisteIp',vote_time='$pVoteTime'";
$this->mDB->query($sql);
$this->mDB->getInsertId ();
return true;
}
else
{
return false;
}
}
unique key (index)之类的唯一性索引,如果有可能是因为你的插入值重复,这个重复很可能是插入了空值,这个空值可能是数据无效造成的