Mysql - 查看值是否已存在

时间:2018-06-14 17:51:16

标签: php mysql

我只是想知道如何解决这个问题。在我的数据库中:here我的值为123.我的代码正在搜索它,但它找不到它。

<html>
 <head>
    <?php
        $userid = 123;
        $con = mysqli_connect("","","*","");
        // Check connection
        if (mysqli_connect_errno())
          {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
          }else{
            echo "Connected";
          }
          echo "123";
        // Perform queries
        $sql_fetch_id = "SELECT * FROM AccessedIds WHERE 64id = '123";
        $query_id = mysqli_query(sql2242953, $sql_fetch_id);
        if(mysqli_num_rows($query_id) ==0) {
            echo "empty";
        }else{
            echo "full";
        }
        mysqli_close($con);
        ?>
  <title>PHP Test</title>
 </head>
 <body>

 </body>
</html> 

Data types

2 个答案:

答案 0 :(得分:0)

您的查询错误,请尝试:

$query_id = mysqli_query($con, $sql_fetch_id);

More information

同样在上面的评论中,删除123之前的单引号。

答案 1 :(得分:0)

您的查询和查询字符串错误。您在查询字符串中缺少单引号(&#39;)。见以下陈述:

$sql_fetch_id = "SELECT * FROM `AccessedIds` WHERE `64id` = '123'";
$query_id = mysqli_query($con, $sql_fetch_id);

希望这有帮助。