PHP MySQL检查重复条目吗? [英] PHP MySQL Check for duplicate entry?

查看:62
本文介绍了PHP MySQL检查重复条目吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何检查数据库中是否已经有重复的条目?我不想阻止它,只是警告.因此,如果它已经存在,它只会发出警告,这取决于用户是否忽略它.
预先感谢!


How can I check if there already is a duplicate entry in the database? I don't want to prevent it, just a warning. So if it already exists it simply gives a warning, it's up to the user to ignore it or not.
Thanks in advance!

推荐答案

$key_id = 123;

$result = mysql_query("SELECT * FROM table WHERE key_id='$key_id'");
$num_rows = mysql_num_rows($result);

if ($num_rows) {
   trigger_error('It exists.', E_USER_WARNING);
}

这篇关于PHP MySQL检查重复条目吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆