如果PHP什么都不做,那它还能做什么

如果PHP什么都不做,那它还能做什么,php,mysql,Php,Mysql,我有PHP中的函数。指令if工作正常,但问题出在其他部分,因为它不起任何作用:/ function getEffectiveVotes($id) { /** Returns an integer **/ $votes = getAllVotes($id); $effectiveVote = $votes[0] - $votes[1]; return $effectiveVote; } $id = $_POST['id']; $ac

我有PHP中的函数。指令if工作正常,但问题出在其他部分,因为它不起任何作用:/

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>';
}

您有一个语法错误

$id = mysql_real_escape_String($id);
应该是

$id = mysql_real_escape_string($id);
als您的elseif语句应该是if语句,并且您的$count变量可以用下面更快的代码替换

    if(mysql_num_rows($ip_sql) > 0){
    echo 
    '
    <script language="javascript">
    alert("message successfully sent")
    </script>
    ';
    }

此外,也可能是从mysql_*函数升级的时候了。据我所知,它们将很快从php中删除。即使现在将“错误报告”设置为“全部”,您仍会看到一条关于它们被弃用的警告。

可能只有这一条!=$count的值是多少?看起来你有一个额外的},我整理了你的代码,如果不是elseif就够了吗?我只是在想,如果不是使用mysql\u real\u escape\u字符串,那么将发布的id按int大小写就够了吗?我想这只是一个大写的拼写错误。因为他没有说任何错误:| php不会为拼写错误的函数抛出错误。事实上,95%的时候,我发现我在试图在脚本中调用函数时拼写错误。函数名在phmmm中不区分大小写!我知道函数名是不敏感的:/@user1950221在我的github上翻找,你应该可以在那里找到一些有用的东西。github.com/r3wt/openex.git