php上传报未定义偏移量,php – 注意:未定义的偏移量:0 in

我得到这个PHP错误,这是什么意思?

Notice: Undefined offset: 0 in

C:\xampp\htdocs\mywebsite\reddit_vote_tut\src\votes.php on line 41

从这段代码:

include("config.php");

function getAllVotes($id)

{

$votes = array();

$q = "SELECT * FROM entries WHERE id = $id";

$r = mysql_query($q);

if(mysql_num_rows($r)==1)//id found in the table

{

$row = mysql_fetch_assoc($r);

$votes[0] = $row['votes_up'];

$votes[1] = $row['votes_down'];

}

return $votes;

}

function getEffectiveVotes($id)

{

$votes = getAllVotes($id);

$effectiveVote = $votes[0] - $votes[1]; //ERROR THROWN HERE

return $effectiveVote;

}

$id = $_POST['id'];

$action = $_POST['action'];

//get the current votes

$cur_votes = getAllVotes($id);

//ok, now update the votes

if($action=='vote_up') //voting up

{

$votes_up = $cur_votes[0]+1; //AND ERROR THROWN HERE

$q = "UPDATE threads SET votes_up = $votes_up WHERE id = $id";

}

elseif($action=='vote_down')

{

$votes_down = $cur_votes[1]+1;

$q = "UPDATE threads SET votes_down = $votes_down WHERE id = $id";

}

$r = mysql_query($q);

if($r)

{

$effectiveVote = getEffectiveVotes($id);

echo $effectiveVote." votes";

}

elseif(!$r) //voting failed

{

echo "Failed!";

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值