0

I have a web form that allows people to sign up for a class. At the bottom of the form is a submit button that says "Sign Up". In my PHP code, I am checking the number of people that have registered for the class. If the count is equal to a specific number, say 60 registrants, I want to change the button to be red and the text is changed to "Class is Full". How do I do this with a CSS if I can only define one button color?

This is my 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;
}

In my PHP code, I have this:

<?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';
}
?>

I know I can't use 'button1' in CSS, but how do I do it so it turns red and says class is full when $count = 60?

chris85
  • 23,846
  • 7
  • 34
  • 51
RickCJ7
  • 39
  • 3
  • 1
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Apr 21 '16 at 21:40

1 Answers1

3

You need to fetch, http://php.net/manual/en/function.mysql-fetch-row.php, the result of your query. Then you will have the value.

Note that you are using a deprecated/removed driver as well.

Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.

So code would be:

<?php
$count = mysql_query("select count(*) from students;");
$array = mysql_fetch_row($count);
if ($array[0] < 60){
    echo'<button type="submit" name="signup">Sign Up';
}else{
    echo'<button1 type="submit" name="">Class is Full';
}
?>

You also should use ids or classs to assign your CSS properties.

...or with the id approach:

<?php
$count = mysql_query("select count(*) from students;");
$array = mysql_fetch_row($count);
if ($array[0] < 60){
    echo'<button type="submit" id="aval" name="signup">Sign Up';
}else{
    echo'<button1 type="submit" name="" id="full">Class is Full';
}
?>

Then the CSS assignments become:

#aval {

and

#full {

or replace # with . if you choose to use a class. If you can have multiple occurrences use classes.

chris85
  • 23,846
  • 7
  • 34
  • 51