This question already has answers here:
Can I mix MySQL APIs in PHP?
                                
                                    (4个答案)
                                
                        
                        
                            Why shouldn't I use mysql_* functions in PHP?
                                
                                    (15个答案)
                                
                        
                                在11个月前关闭。
            
                    
我似乎无法使代码正常工作,以确定如何检查Mysql表中是否存在记录。
我在这方面不是很好,但我正在学习。
我想检查在我的表格中是否存在称为用户的特定条形码。

当我执行以下代码时,出现以下错误。

Fatal error: Uncaught Error: Call to undefined function mysql_query() in C:\xampp\htdocs\watermeters\see.php:14 Stack trace: #0 {main} thrown in C:\xampp\htdocs\watermeters\see.php on line 14


请参见下面的代码。
有人可以帮我这个代码吗?


<?php


$link = mysqli_connect("localhost", "root", "", "watermeter");

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}



$query = "SELECT barcode from users where barcode='5645454'";
$result = mysql_query($link, $query);

if(mysql_num_rows($result) > 0)
{
    // row exists. do whatever you would like to do.
} else {

    // row does not exists. do whatever you would like to do.
}




// Close connection
mysqli_close($link);

?>

最佳答案

您正在混合mysql和mysqli

使用mysqli_query

关于php - 如何检查记录是否存在于Mysql表中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55316517/

10-09 21:57