gpt4 book ai didi

php - 检查数据库中的现有用户名

转载 作者:行者123 更新时间:2023-12-01 00:28:54 24 4
gpt4 key购买 nike

我有注册表单,它在“tblusers”->“用户名”中保存用户信息,但它不检查用户是否已经存在,所以目前用户可以使用相同的用户名注册,这是一个巨大的困惑。

所以我需要检查 MySQL 数据库中是否存在注册时的“用户名”。知道如何使用 PHP - MySQL,甚至是 javascript 来做到这一点。

这是我在提交表单时执行的代码:

    check_token ();
$_SESSION['currency'] = $currency;
$clientid = addclient ($firstname, $lastname, $companyname, $email, $address1, $address2, $city, $state,
$postcode, $country, $phonenumber, $password, $securityqid, $securityqans, $sendemail);
//print "New clientid=" . $clientid . "<br>";
update_query ('tblclients', array ('notes' => $notes, 'status' => $status, 'credit' => $credit, 'salesOperatorId' => $salesOperatorId,
'taxexempt' => $taxexempt, 'latefeeoveride' => $latefeeoveride, 'overideduenotices' => $overideduenotices, 'country' => 'US',
'language' => $language, 'billingcid' => $billingcid, 'lastlogin' => '00000000000000'), array ('id' => $clientid));
//print "New clientid now=" . $clientid . "<br>";
savecustomfields ($clientid, $customfield);
$result = select_query ('tblusers', 'ID', array ('ClientID' => $clientid));

// adding user to the DB at same time as client is being added ...
$datenowtimestamp = date("Y-m-d H:i:s");
$table91 = 'tblusers';
$array91 = array ('ClientID' => $clientid, 'firstname' => $userfirstname, 'lastname' => $userlastname, 'email' => $useremail,
'username' => $username, 'password' => $password, 'searchdelivery' => 'Criminal', 'reporttiming' => 'Instant',
'deliverymethod' => 'email', 'Created' => $datenowtimestamp,
'phonenumber' => $phonenumber, 'orderreports' => 1, 'viewallreports' => 1, 'viewpricing' => 1,
'restrictreportview' => 0, 'gatewayaccess' => 0);
insert_query ($table91, $array91);

if($data = mysql_fetch_array ($result))
$userid = $data['ID'];
$header = 'Location: clientsusers.php?clientid=' . $clientid;
//print $header . "<br>";
header ($header);
exit ();

最佳答案

执行此操作的正确方法可能是在用户表的 username 列上添加唯一索引:

CREATE UNIQUE INDEX username_index ON users (username);

替代方案(检查您的 PHP 代码)可能会出现两个人同时尝试使用相同用户名注册的问题。

关于php - 检查数据库中的现有用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9084591/

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