gpt4 book ai didi

php - 如何防止重复的用户名和电子邮件数据?

转载 作者:行者123 更新时间:2023-11-30 22:13:13 25 4
gpt4 key购买 nike

<分区>

我一直在制作登录/注册系统,我即将完成代码的注册部分。我遇到的唯一问题是如何使用户无法使用重复的用户名和电子邮件注册。我希望它能正常工作,这样我的数据库就不会接受信息,并且会告知用户错误。

<!-- daftar -->
<section id="daftar" style="background: #333;">
<div class="container">
<div class="row text-center">
<div class="col-lg-10 col-lg-offset-1">
<h2 style="font-family:Font Juice; font-size:50px; color:#ccc; padding: 20px;">Daftar Baru</h2>
<hr class="small">
<div class="row">
<div class="col-lg-8 col-lg-offset-2" >
<form name="contactForm" method="post" id="contactForm" action="<?php $_SERVER['PHP_SELF'];?>">
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<input type="text" class="form-control" placeholder="Nama Anda" name="t1" id="t1" required data-validation-required-message="Input nama anda.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<input type="email" class="form-control" placeholder="Email" name="t2" id="t2" required data-validation-required-message="Input alamat email.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<input type="text" class="form-control" placeholder="Username" name="t3" id="t3" required data-validation-required-message="Input username untuk login">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<input type="password" class="form-control" placeholder="Password" name="t4" id="t4" required data-validation-required-message="Input password untuk login">
<p class="help-block text-danger"></p>
</div>
</div>

<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<input type="password" class="form-control" placeholder="Konfirmasi Password" name="t5" id="t5" required data-validation-required-message="Konfirmasi Password">
<p class="help-block text-danger"></p>
</div>
</div>

<script type="text/javascript">
window.onload = function () {
document.getElementById("t4").onchange = validatePassword;
document.getElementById("t5").onchange = validatePassword;
}
function validatePassword(){
var t4=document.getElementById("t4").value;
var t5=document.getElementById("t5").value;
if(t4!=t5)
document.getElementById("t5").setCustomValidity("Passwords tidak Sama, Coba Lagi");
else
document.getElementById("t5").setCustomValidity('');
}
</script>

<div class="row">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label class="checkbox-inline">
<h5 style="color:#fff; font-family: BebasNeueRegular; font-size: 24px">Dengan menekan tombol " Daftar "<br> Saya Setuju dengan <a href="#">Kebijakan dan Ketentuan</a> yang berlaku.</h5>
</label>
</div>

<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-primary btn-lg" style="font-family:'BebasNeueRegular'; font-size:20px; text-shadow: 0 2px 2px rgba(0, 0, 0, 0.3);" name="btnSimpan" id="btnSimpan"> <span class="glyphicon glyphicon-list"></span> &nbsp;&nbsp;Daftar&nbsp;&nbsp;</button>
<br><br><br>
</div>
</div>
<div id="success"></div>
</form>

<?php
if(isset($_POST['btnSimpan'])){
$q = $op->save("tb_user","nama_user,email_user,username,password","'".$_POST['t1']."','".$_POST['t2']."','".$_POST['t3']."','".md5($_POST['t4'])."'");
if($q){
echo "<div class='alert alert-success'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>
<strong>Success!</strong> Data berhasil disimpan. Silahkan klik tombol Mulai Bermain.</div>";
}else{
echo "<div class='alert alert-danger' >
<a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>
<strong>Error !</strong> Data gagal disimpan</div>";
}
}
?>
</div>
</div>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com