我有PHP的功能。指令“if”完美地运行,但问题在于elseif部分,因为它什么都不做:/
function getEffectiveVotes($id) {
/**
Returns an integer
**/
$votes = getAllVotes($id);
$effectiveVote = $votes[0] - $votes[1];
return $effectiveVote;
}
$id = $_POST['id'];
$action = $_POST['action'];
//get the current votes
$cur_votes = getAllVotes($id);
//ok, now update the votes
$ip = $_SERVER['REMOTE_ADDR'];
if ($_POST['id']) {
$id = $_POST['id'];
$id = mysql_real_escape_String($id);
$ip_sql = mysql_query("select ip_add from Voting_IP where mes_id_fk='$id' and ip_add='$ip'");
$count = mysql_num_rows($ip_sql);
if ($count == 0) {
if ($action == 'vote_up') //voting up
{
$votes_up = $cur_votes[0] + 1;
$q = "UPDATE entries SET votes_up = $votes_up WHERE id = $id";
$sql_in = "insert into Voting_IP (mes_id_fk,ip_add) values ('$id','$ip')";
mysql_query($sql_in);
}
elseif($action == 'vote_down') //voting down
{
$votes_down = $cur_votes[1] + 1;
$q = "UPDATE entries SET votes_down = $votes_down WHERE id = $id";
$sql_in = "insert into Voting_IP (mes_id_fk,ip_add) values ('$id','$ip')";
mysql_query($sql_in);
}
}
elseif($count !== 0) {
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
}
} ?>
问题出在这一部分。是在错误的地方还是错误的语法?我没有任何错误。
elseif($count!==0){
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
}
答案 0 :(得分:0)
你有语法错误
$id = mysql_real_escape_String($id);
应该是
$id = mysql_real_escape_string($id);
此外,您的elseif
声明应该是if
声明,而您的$count
变量可以用下面更快的代码替换
if(mysql_num_rows($ip_sql) > 0){
echo
'
<script language="javascript">
alert("message successfully sent")
</script>
';
}
此外,也可能是从mysql_*
功能升级的时候了。他们将很快从我理解的PHP中删除。即使现在将错误报告设置为所有,您也会看到关于它们被弃用的警告。