I insert a name from a form into a database that represents the participants of a workshop. In the workshop there is only room for 30 people and try to limit that with the COUNT (*) function. My problem is that the form keeps sending data even if the database already has 30 entries. Thanks for your help.
<?php
$link = mysqli_connect("localhost", "user", "pass", "base");
if($link === false){
die("ERROR: No se puede conectar. " . mysqli_connect_error());
}
$name = mysqli_real_escape_string($link, $_REQUEST['name']);
$res = mysqli_query("SELECT COUNT(*) as cnt FROM 'taller1' ");
$row = mysqli_fetch_assoc($res);
if($row['cnt']<30){
$sql = "INSERT INTO taller1 (name) VALUES ('".$name."')";
if(mysqli_query($link, $sql)){
echo "Su registro se ha realizado correctamente.";
}
else{
echo "ERROR: no se pudo añadir $sql. " . mysqli_error($link);
}
}
else{
echo "Taller lleno";
}
mysqli_close($link);
?>