我有一個web表單,允許人們註冊一個類。表單底部是一個提交按鈕,顯示「註冊」。在我的PHP代碼中,我正在檢查爲該課程註冊的人數。如果計數等於特定的數字,例如60個註冊人,我想將該按鈕更改爲紅色,文本更改爲「Class is Full」。如果我只能定義一個按鈕顏色,如何用CSS做到這一點?基於數據庫查詢的不同按鈕顏色
這是我的CSS:
button {
padding: 19px 39px 18px 39px;
color: #FFF;
background-color: #4bc970;
font-size: 18px;
text-align: center;
font-style: normal;
border-radius: 5px;
width: 100%;
border: 1px solid #3ac162;
border-width: 1px 1px 3px;
box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
margin-bottom: 10px;
}
button1 {
padding: 19px 39px 18px 39px;
color: #FFF;
background-color: #ff0000;
font-size: 18px;
text-align: center;
font-style: normal;
border-radius: 5px;
width: 100%;
border: 1px solid #3ac162;
border-width: 1px 1px 3px;
box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
margin-bottom: 10px;
}
在我的PHP代碼,我有這樣的:
<?php
$count = mysql_query("select count(*) from students;");
if ($count < 60){
echo'<button type="submit" name="signup">Sign Up';
}else{
echo'<button1 type="submit" name="">Class is Full';
}
?>
我知道我不能在CSS中使用 '按鈕1' ,但我該怎麼做,所以它變成了紅色,並說當$ count = 60時課程已滿?
請[停止使用'mysql_ *'函數](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 [這些擴展](http://php.net/manual/en/migration70.removed-exts-sapis.php)已在PHP 7中刪除。瞭解[編寫](http://en.wikipedia.org/ wiki/Prepared_statement)語句[PDO](http://php.net/manual/en/pdo.prepared-statements.php)和[MySQLi](http://php.net/manual/en/mysqli.quickstart .prepared-statements.php)並考慮使用PDO,[這真的很簡單](http://jayblanchard.net/demystifying_php_pdo.html)。 –