gpt4 book ai didi

php - 如何避免在 php 表单中多次输入相同的用户名?

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

我对此感到震惊!我需要避免多次输入相同的用户名..并且如果发生这种情况,还要通知错误的密码..这是代码:我是新手,所以请帮助我..

<?php 
include('include/header.php');
if(isset($_POST['donor']) || $_POST['donor']!=""){
$msg = $productFetch->addproduct($_REQUEST);
}
if(isset($_POST['reghos']) || $_POST['reghos']!=""){
$msg = $recepientFetch->addrecepient($_REQUEST);
$msg = "Hospital Registered Successfully";
}
if(isset($_POST['hospitallogin'])){
$username = $_POST['name'];
$password = md5($_POST['password']);
$qry = "select * from `hospitaluser` where `firstname`='$username' and hospitaluserpassword='$password' and `hospitaluserlevel`='1'";

if(mysql_num_rows(mysql_query($qry))>0){
$hospital_user = mysql_fetch_object(mysql_query($qry));
$_SESSION['hospital_user']=$hospital_user->firstname;
$_SESSION['hospital_user_id']=$hospital_user->id;
$msg = "Successfully Login";
}
}
$qry="";
if(isset($_POST['hospitalregister'])){
$firstname = $_POST['firstname'];
$password = md5($_POST['hospitaluserpassword']);
$cpassword = md5($_POST['hospitalusercpassword']);
if($password==$cpassword){
$qry = "select * from `hospitaluser` where `firstname`='$firstname' and `hospitaluserlevel`='1'";

if(mysql_num_rows(mysql_query($qry))<=0){
$msg = $hospitaluserFetch->addhospitaluser($_REQUEST);
$msg = "Successfully Registered";
}else{
$msg = "The User Name Is Alread Exist! Choose Another One!";
}
}else{
$msg="Password Doesn't Match";
}
}

最佳答案

在 mysql 中尝试一下:

ALTER TABLE hospitaluser ADD UNIQUE (firstname);

这将在 firstname 列上创建唯一索引,从而防止您两次插入相同的用户名。

如需更多帮助 - 您可以添加 addhospitaluser 的代码吗?

关于php - 如何避免在 php 表单中多次输入相同的用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20804161/

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