php - mysql select 有3个条件问题

标签 php mysql

你好,我的问题是,如果我更改我的 IP,但我有相同的 cookie,它会转到 else 语句并在应该失败时执行查询。我不知道为什么它在计算时不使用 $cookie 参数。

<?php
    require_once('../core/dbconfig.php');
    $dbc = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASS, DB_NAME);
    $ip_adress=$_SERVER['REMOTE_ADDR'];
    $cookie=$_COOKIE['Cookie'];
    $id_user=$_POST['id_user'];

    $query="Select * from IP_Cookie_Verify where ID_User='$id_user' and Cookie='$cookie' and IP='$ip_adress'";
    $result=mysqli_query($dbc,$query) or die("query failed: " . mysqli_error($dbc));
     if($row = mysqli_fetch_array($result))
     {      
            echo'fail';             
     }
     else
     {
     $query="Insert into IP_Cookie_Verify (IP,ID_User,Cookie) VALUES ('$ip_adress','$id_user','$cookie')";
                    $result=mysqli_query($dbc,$query) or die("query failed: " . mysqli_error($dbc));


     $queryz="Update `users` SET Voturi=Voturi+1 where id='$id_user'";
                    $resultz=mysqli_query($dbc,$queryz) or die("query failed: " . mysqli_error($dbc));

        $query="Select * from `users` where id='$id_user'";
        $result=mysqli_query($dbc,$query) or die("query failed: " . mysqli_error($dbc));
        while ($row = mysqli_fetch_array($result))
                    {
                    $voturi=$row['Voturi'];
                    }
                    echo''.$voturi.'';
     }

最佳答案

在查询中检查 IP 地址。但是,如果您更改它,查询将失败并且不返回任何结果,因此您的 else 条件将被执行。

像这样更改您的查询:

$query="Select * from IP_Cookie_Verify where ID_User='$id_user' and (Cookie='$cookie' OR IP='$ip_adress')";

关于php - mysql select 有3个条件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21829420/

相关文章:

php - 来自 DB、php 和 .htaccess 的 URL 友好

mysql - 如何在mysql中正确创建程序?

php - Codeigniter CORS 策略 : No 'Access-Control-Allow-Origin' error How to resolve?

php - 检查我的年龄范围是否与数据库中存储的 'date of birth' 匹配

PHP 选择多个表作为数组

php - Mac上AMPPS下phpMyAdmin的root用户默认密码是多少?

MySQL/存储 MySQL 凭据

mysql - Spring Security 是否需要/推荐使用 innodb?

MySQL Cluster是NoSQL技术吗?

php - 记录在数据库上执行了哪些事件的方法? -MySQL/PHP