本文介绍了如何避免在php mysqli中插入重复记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何避免在PHP MYSQLi中插入重复记录?这是我的脚本:
How do I avoid duplicate records insertion in PHP MYSQLi?this my script :
$nama=$_POST['nama'];
$member=$_POST['member'];
$peserta=$_POST['peserta'];
$tour=$_POST['tour'];
mysqli_query($conn,"insert into gathering (nama, member, peserta, tour) values ('$nama', '$member', '$peserta', '$tour')");
header('location:index.php');
推荐答案
以下代码将帮助您插入唯一数据:
Below code will help you inserting unique data:
$result = mysqli_query($conn, "SELECT nama, member, peserta, tour FROM gathering where nama = '$nama' and member = '$member' and peserta='$peserta' and tour='$tour'")
$total = mysqli_num_rows($result);
if($total==0)
{
mysqli_query($conn,"insert into gathering (nama, member, peserta, tour)
values ('$nama', '$member', '$peserta', '$tour')");
}
这篇关于如何避免在php mysqli中插入重复记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!