PHP将表单上的注册限制为一定数量的用户隐藏/显示表单 [英] PHP Limit registration on form to a certain amount of users hide/show form
本文介绍了PHP将表单上的注册限制为一定数量的用户隐藏/显示表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谢谢,
查理
<?php
$ connection = mysqli_connect(host,username,password,database);
$ sql =从database_users中选择COUNT(*);
$ stmt = $ connection-> prepare($ sql);
$ stmt-> execute();
$ res = $ stmt-> get_result();
$ users = $ res-> fetch_array(MYSQLI_ASSOC);
if($ users ['COUNT(*)']< 4){
?>
// html转到这里,在php标签之外
<?php
} else {
echo对不起,您已达到用户帐户限制。;
};
?>
解决方案
试试这个,
<?php
mysql_connect(host,username,password);
mysql_select_db(database);
$ sql =select * from database_users;
$ query = mysql_query($ sql);
if(mysql_num_rows($ query)< 4)
{
while($ r = mysql_fetch_array($ query))
{
?> ;
// HTML转到此处
<?php
}
}
else
{
echo对不起,您已到达用户账户限额。
}
?>
I am having trouble. I'm not very good at PHP - I have some code which is object orientated. I would like to change this code into standard PHP code, can someone please help. I need it to be standard PHP.
Thanks,
Charlie
<?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.";
};
?>
解决方案
Try this one,
<?php
mysql_connect("host", "username", "password");
mysql_select_db("database");
$sql = "select * from database_users";
$query = mysql_query($sql);
if(mysql_num_rows($query) < 4)
{
while($r = mysql_fetch_array($query))
{
?>
// HTML Goes Here
<?php
}
}
else
{
echo "Sorry, you have reached the user account limit.";
}
?>
这篇关于PHP将表单上的注册限制为一定数量的用户隐藏/显示表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文