奇怪的问题,请大家帮忙看看在线等!

simplegift 2003-08-14 12:26:49
intro.php:
<?
include_once("inc.php");
$user = new User;
$vote = new Vote;

$user->getUser($user_id);

$vister_ip=$REMOTE_ADDR;
$vote_time= date(" Y-m-d, h:i:s");


if($submit)
{
if($vote->addVote($user_id,$vister_ip,$vote_time))
{
$vote->updateNoseCount($user_id);
echo "<script>alert('欢迎您参与投票!');window.history.back();</script>";
}
else
echo "<script>alert('抱歉您的投票失败!');window.history.back();</script>";


}



?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<form action="intro.php?user_id=<?=$user_id;?>" method=post>
<body bgcolor="#FFFFFF" text="#000000">
<table width="773" border="1" cellspacing="1" cellpadding="3" align="center">
<tr>
<td width="255" valign="top"><img src="02.jpg" width="238" height="284"><br>
目前人气:<?echo $user->mNoseCount;?><br>
所在世界:<?echo $user->mGameType;?><br>
游戏角色:<?echo $user->mGameRoll;?> <br>
<br>
<br>
</td>
<td width="506" valign="top"> <b>玩家详细资料 </b>
<hr>
<p> 昵称:<?echo $user->mNickname;?><br>
性别:<?echo $user->Gmender ;?><br>
年龄:<?echo $age;?> <br>
血型:<?echo $user->mBloodType ;?><br>
体重: <?echo $user->mAvoirdupois;?><br>
体型:<?echo $array_body[$user->mBodilyForm];?> <br>
星座:<?echo $array_astro[$user->mConstellation];?><br>
爱好:<?echo $user->mLove;?> <br>
oicq:<?echo $user->mOicq;?> icq:<?echo $usr->mIcq;?> msn:<?echo $user->mMsn;?> <br>
所在地:<?echo $user->mNation;echo $user->mProvince;echo $user->mCity;?> </p>
<p>【自我介绍】<br>
<?echo $user->mUserIntro;?> <br>
【给玩家的话】<br>
<?echo $user->mToEvery;?> <br>
</p>
<input type="submit" name="submit" value="确定投票" width="114" height="30"></td>

</tr>
</table>
</form>
</body>
</html>

class.vote.php:
<?
//class.vote.php
class Vote
{
var $mUserId;
var $mVisterIp;
var $mVoteTime;
var $mDB;

function Vote()
{
$this->mDB = new mysql;
}


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 ();

}


function updateNoseCount($pUserId)
{

$sql="update member set nose_count=nose_count+1 where user_id='$pUserId'";
$this->mDB->query($sql);
return $this->mDB->getInsertId ();
}

function checkVote($pUserId,$pVisterIP,$pVoteTime)
{
$sql="select * from vote where vister_ip='$pVisterIP' and user_id='$pUserId' and vote_time> date_sub(now(),interval 1 day)";
$result=$this->mDB->query($sql);
if( $this->mDB->getNumRows($result)>0)
return false;
else
return true;
}


}

?>

为什么每次执行后总是输出:抱歉您的投票失败!
$vote->addVote($user_id,$vister_ip,$vote_time)已经被执行
...全文
44 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
babystudio 2003-08-15
  • 打赏
  • 举报
回复
你的表中有没有
unique key (index)之类的唯一性索引,如果有可能是因为你的插入值重复,这个重复很可能是插入了空值,这个空值可能是数据无效造成的
bonniewater 2003-08-14
  • 打赏
  • 举报
回复
function addVote($pUserId,$pVisteIp,$pVoteTime)
{
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;
}
}
bluemeteor 2003-08-14
  • 打赏
  • 举报
回复
$sql="select * from vote where vister_ip='$pVisterIP' and user_id='$pUserId' and vote_time> date_sub(now(),interval 1 day)";

估计是你这个语句返回了值大于0了

同一IP和ID 24小时只能投一次
xuzuning 2003-08-14
  • 打赏
  • 举报
回复
$vote_time= date(" Y-m-d, h:i:s"); // 这个在显示时没有问题
但是在插入时是错误的格式,建议
$sql="insert into vote set user_id='$pUserId',vister_ip='$pVisteIp',vote_time=NOW()";

simplegift 2003-08-14
  • 打赏
  • 举报
回复
现在的问题时:
只有当表vote中没有记录时,addvote()才会执行,怎么回事?
simplegift 2003-08-14
  • 打赏
  • 举报
回复
class.mysql.php

<?
// 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);
}
}
?>
bluemeteor 2003-08-14
  • 打赏
  • 举报
回复
加个return true;

楼主把你的mysql这个类帖出来看看吧,学习一下
$this->mDB = new mysql;
bonniewater 2003-08-14
  • 打赏
  • 举报
回复
return ture;
错了
return true;
pilicat 2003-08-14
  • 打赏
  • 举报
回复
对,先按楼上兄台的方法一试,另外,你投票后看看数据库中有没有添加了数据了,要是已经加了,多半是函数的返回值有问题。
bonniewater 2003-08-14
  • 打赏
  • 举报
回复
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;
}
这样试试

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧