Limitar numero de inserções no banco
Pessoal to com este codigo que deveria barrar o cadastro quando o numero chegar a 2.
Ele mostra a mensagem que o cadastro máximo foi atingido so que deixa inserir como faço para não aparecer a tela de inserção?
Segue o codigo. Obrigado pela ajuda
Ele mostra a mensagem que o cadastro máximo foi atingido so que deixa inserir como faço para não aparecer a tela de inserção?
Segue o codigo. Obrigado pela ajuda
<?php require_once('Connections/semad.php'); ?>
<?php
$sql5 = mysql_query("SELECT * FROM candidato WHERE evento = 'abertura'");
//depois ve o nº de registros que a pesquisa resultou
$novo=mysql_num_rows($sql5);
echo($novo);
$max=2; // nº maximo de registros no DB
if ($novo==$max)
echo ("Minicurso com o número máximo de participantes atingido");
if ($novo5<>$max)
{
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO candidato (nome, cpf, evento, efe) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['nome'], "text"),
GetSQLValueString($_POST['cpf'], "text"),
GetSQLValueString($_POST['evento'], "text"),
GetSQLValueString($_POST['efe'], "text"));
mysql_select_db($database_semad, $semad);
$Result1 = mysql_query($insertSQL, $semad) or die(mysql_error());
$insertGoTo = "sucesso.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Faculdades Integradas de Cataguases</title>
</head>
<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Nome:</td>
<td><input type="text" name="nome" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Cpf:</td>
<td><input type="text" name="cpf" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Evento:</td>
<td><input type="text" name="evento" value="Abertura" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Efe:</td>
<td><input type="text" name="efe" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insert record"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html>
comentários (0)
suspender
Lista de Respostas:
01/09/2009 12:07am
(~16 anos atrás)
(~16 anos atrás)
Para bloquear voce verifica quantos existem, se o numero for maior voce bloqueia, exemplo
$sql5 = mysql_query("SELECT * FROM candidato WHERE evento='abertura'");
$novo = mysql_num_rows($sql5);
if($novo>=2){
header("location: acabou_inscricao.php");
exit;
}
dai na pagina que faz a inscricao vc pode fazer algo tipo
$sql5 = mysql_query("SELECT * FROM candidato WHERE evento='abertura'");
$novo = mysql_num_rows($sql5);
if($novo>=2){
echo "As inscricoes acabaram";
}else{
echo "Faca sua inscricao";
}
espero ter ajudado
$sql5 = mysql_query("SELECT * FROM candidato WHERE evento='abertura'");
$novo = mysql_num_rows($sql5);
if($novo>=2){
header("location: acabou_inscricao.php");
exit;
}
dai na pagina que faz a inscricao vc pode fazer algo tipo
$sql5 = mysql_query("SELECT * FROM candidato WHERE evento='abertura'");
$novo = mysql_num_rows($sql5);
if($novo>=2){
echo "As inscricoes acabaram";
}else{
echo "Faca sua inscricao";
}
espero ter ajudado
03/09/2009 11:27am
(~16 anos atrás)
(~16 anos atrás)
Eu tenho interesse nesse código também...
Um amigo me falou que era possível fazer isso no MySQL, mais já procurei e não encontrei nenhum site que mostrasse o procedimento.
Acredito que a melhor forma é de acordo com o código acima, pois faz a limitação de dados dentro do BD.
Valeu!!
Um amigo me falou que era possível fazer isso no MySQL, mais já procurei e não encontrei nenhum site que mostrasse o procedimento.
Acredito que a melhor forma é de acordo com o código acima, pois faz a limitação de dados dentro do BD.
Valeu!!
