这里我有要创建用户的代码,他们必须输入admin给出的一个访问代码。该访问代码受到某些用户的限制,例如rpcinfo -p 192.168.13.80
或10
。之后它会显示20
之类的错误。所以到现在为止,它工作正常。
现在,如果用户尝试输入管理员未提供的访问代码,则必须显示your accesscode is limited
之类的错误消息。
这是我的代码:
your accesscode is wrong
答案 0 :(得分:0)
您能否向我们提供有关您问题的更多信息?什么不起作用?在你的循环中尝试一些“var_dump()”来知道你是否通过,这样你就可以告诉我们问题出在哪里了!
但我首先看到的是:
if(! $chk_username = $DB->get_record_sql($chk_sql, array($_POST['username'])) )
在这里:
if($result = $DB->insert_record('user', $insert_record))
您应该使用“==”或“===”,因为使用“=”表示您为“$ chk_username”和“result”赋值。
如果你想显示flash信息,这里有一些你可以使用的librairie,这只是为了你的信息: https://github.com/plasticbrain/PhpFlashMessages
如果您想在JS中执行此操作,可以使用:https://github.com/CodeSeven/toastr
希望它有所帮助!
答案 1 :(得分:0)
我改变了这样的条件
<?php
require('../config.php');
require_once($CFG->dirroot . '/user/editlib.php');
$errorMessage = '';
$successMessage = '';
if(isset($_SESSION['successMessage']))
{
$successMessage = $_SESSION['successMessage'];
unset($_SESSION['successMessage']);
}
if (isset($_POST['register'])) {
$errors = array();
$data = array();
$chk_sql = "SELECT * FROM {user} u where username = ?";
if (!empty($chk_sql) ) {
$errorMessage='Username already taken';
}
if(!$chk_username = $DB->get_record_sql($chk_sql, array($_POST['username']))
)
{
$secret = $_POST['secret'];
$access_code_sql = "SELECT * FROM {accesscode} WHERE random_no= ? and
status=1";
if($chk_secret = $DB->get_record_sql($access_code_sql, array($secret)) )
{
if ( $chk_secret->used >= $chk_secret->number ) {
$errorMessage = "your access code limit completed..";
}else
{
$cadminid = $chk_secret->cadmin_id;
$clientid = $chk_secret->clientid;
$DB->execute("UPDATE {accesscode} SET used = used+1 WHERE random_no = '$secret'");
$insert_record = new stdClass();
$insert_record->firstname = $_POST['firstname'];
$insert_record->lastname = $_POST['lastname'];
$insert_record->username = $_POST['username'];
$insert_record->secret = $secret;
$insert_record->password = password_hash($_POST['password'],
PASSWORD_DEFAULT);
$insert_record->timecreated = time();
$insert_record->maildigest = $cadminid;
$insert_record->maildisplay = $clientid;
$insert_record->idnumber = 1;
$insert_record->mnethostid = 1;
$insert_record->confirmed = 1;
$insert_record->email = $_POST['email'];
if($result = $DB->insert_record('user', $insert_record))
{
$_SESSION['successMessage'] = "record created successfully";
header('Location: register.php');
}
else
$errorMessage = "error! can you please try again";
}
}
else
$errorMessage = "your access code is wrong..";
}
}
?>
它正在运作..