限制用户注册的代码-隐藏/显示表格php [英] Code to limit user registration - hide/show form php
本文介绍了限制用户注册的代码-隐藏/显示表格php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚开始学习PHP-不太好.我创建了一个表单(请参见下文),我希望人们签署该表单,但我希望将此表单限制为一定数量的成员.例如,当4个用户可以注册时,它会隐藏该表单并显示一条消息,抱歉,您已经达到用户帐户限制".
I've just started to learn PHP - Not very good. I have created a form (see below) which I would like people to sign up to but I would like to limit this to a certain number of members. For example 4 users can sign up when it reaches that amount it will hide the form and display a message saying "sorry, you have reached the user account limit."
<form action="users.php?new=1" method="post">
<input type="hidden" name="action" value="newUser"/>
<input type="hidden" name="id" value="0"/>
<fieldset>
<legend>Add new user</legend>
<?php if(isset($msg)) { echo $msg;}?>
<p>
<label>Full name: </label>
<input name="name" value="<?php if(isset($name)) { echo $name;}?>" style="width:400px;"/>
</p>
<p>
<label>Email: </label>
<input name="email" value="<?php if(isset($email)) { echo $email;}?>" style="width:400px;"/>
</p>
<p>
<label>Password: </label>
<input name="password" type="password" value="" style="width:400px;"/>
</p>
<p>
<label>Phone number: </label>
<input name="phone" value="<?php if(isset($phone)) { echo $phone;}?>" style="width:400px;"/>
</p>
<p>
<label>User level:</label>
<select name="access" class="dropdown">
<option value="no" <?php if(isset($access)) { if ($access =='no'){ echo ' selected="selected" ';}}?>>User</option>
<option value="yes" <?php if(isset($access)) { if ($access =='yes'){ echo ' selected="selected" ';}}?>>Admin</option>
</select>
注意:管理员用户将拥有对所有区域的完全访问权限.
Note: Admin users will have full access to all areas.
请有人可以帮助我!代码会很可爱!
Please can someone help me! Code would be lovely!
谢谢, 查理
推荐答案
<?php
$connection=mysqli_connect("host", "username", "password", "database");
$sql="SELECT COUNT(*) from database_users";
$stmt = $connection->prepare($sql);
$stmt->execute();
$res = $stmt->get_result();
$users = $res->fetch_array(MYSQLI_ASSOC);
if ($users['COUNT(*)'] < 4) {
?>
// html goes here, outside of the php tags
<?php
} else {
echo "Sorry, you have reached the user account limit.";
};
?>
这篇关于限制用户注册的代码-隐藏/显示表格php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文