doushi3454 2019-03-23 17:32
浏览 253
已采纳

如何检查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 2019-03-23 17:36
    关注

    You are mixing mysql and mysqli

    Use mysqli_query

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看