doushi3454
2019-03-23 17:32 阅读 216
已采纳

如何检查Mysql表中是否存在记录[重复]

This question already has an answer here:

i can't seem to get the code working to determine how to check if a record exists in Mysql table. Im not very good at this but i'm learning. i would like to check if a certain barcode exists in my table called users.

i get the following error when i execute the code below.

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

See the code below. Can someone help me with this code?


<?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);

?>

</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    drfls28608 drfls28608 2019-03-23 17:36

    You are mixing mysql and mysqli

    Use mysqli_query

    点赞 评论 复制链接分享

相关推荐