Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/10/2014, 15:25
expecimen
 
Fecha de Ingreso: octubre-2006
Ubicación: Ciudad Ojeda, Venezuela
Mensajes: 123
Antigüedad: 20 años
Puntos: 0
Información Limitar la cantidad de registro PHP y SQL

Hola a todos, bien en esta ocasión vengo con esta problemática:

tengo un sistema de registro en base de datos en PHP y MySQL y pues no es algo del otro mundo pero lo que busco que solo se registren 5 usuarios es decir que luego de que esos 5 usuarios se registre no me permite mas registro en la base de datos. La verdad no se código utilizar.

Se que es con la función LIMIT pero he estado jugando con dicha función pero no me resulta.

Acá les dejo el código de registro PHP, esperando a que me puedan ayudar:

Código PHP:
<?php
@setlocale(LC_ALL,'es_ES@euro','es_ES','esp');
date_default_timezone_set('America/Caracas');
    
//Start session
    
session_start();
    
    
//Include database connection details
    
require_once('config.php');
    
    
//Array to store validation errors
    
$errmsg_arr = array();
    
    
//Validation error flag
    
$errflag = false;
    
    
//Connect to mysql server
    
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!
$link) {
        die(
'Failed to connect to server: ' . mysql_error());
    }
    
    
//Select database
    
$db = mysql_select_db(DB_DATABASE);
    if(!
$db) {
        die(
"Unable to select database");
    }
    
    
//Function to sanitize values received from the form. Prevents SQL injection
    
function clean($str) {
        
$str = @trim($str);
        if(
get_magic_quotes_gpc()) {
            
$str = stripslashes($str);
        }
        return 
mysql_real_escape_string($str);
    }
    
    
//Sanitize the POST values
    
$empresa = clean($_POST['empresa']);
    
$estado = clean($_POST['estado']);
        
$ciudad = clean($_POST['ciudad']);
        
$nombres = clean($_POST['nombres']);
        
$apellidos = clean($_POST['apellidos']);
        
$cedula1 = clean($_POST['cedula1']);
        
$cedula2 = clean($_POST['cedula2']);
        
$telefono = clean($_POST['telefono']);
        
$login = clean($_POST['login']);
    
$password = clean($_POST['password']);
    
$cpassword = clean($_POST['cpassword']);
    
$email = clean($_POST['email']);
    
    
//Input Validations
    
if($empresa == '') {
        
$errmsg_arr[] = 'Falta Empresa';
        
$errflag = true;
    }
    if(
$ciudad == '') {
        
$errmsg_arr[] = 'Falta Ciudad';
        
$errflag = true;
    }
    if(
$nombres == '') {
        
$errmsg_arr[] = 'Falta Nombres';
        
$errflag = true;
    }
      if(
$apellidos == '') {
        
$errmsg_arr[] = 'Falta Apellidos';
        
$errflag = true;
    }

        if(
$cedula2 == '') {
        
$errmsg_arr[] = 'Falta Cedula';
        
$errflag = true;
    }
    if(
$telefono == '') {
        
$errmsg_arr[] = 'Falta Telefono';
        
$errflag = true;
    }
     if(
$login == '') {
        
$errmsg_arr[] = 'Falta Login';
        
$errflag = true;
    }
    if(
$password == '') {
        
$errmsg_arr[] = 'Falta Password';
        
$errflag = true;
    }
    if(
$cpassword == '') {
        
$errmsg_arr[] = 'Confirme Password';
        
$errflag = true;
    }
    if( 
strcmp($password, $cpassword) != 0 ) {
        
$errmsg_arr[] = 'Passwords no coiciden';
        
$errflag = true;
    }
        if(
$email == '') {
        
$errmsg_arr[] = 'Falta Email';
        
$errflag = true;

    }
    
    
    
//Check for duplicate cedula2 ID
    
if($cedula2 != '') {
        
$qry = "SELECT * FROM datos_stands WHERE cedula2='$cedula2'";
        
$result = mysql_query($qry);
        if(
$result) {
            if(
mysql_num_rows($result) > 0) {
                
$errmsg_arr[] = '<b>EL NUEMRO DE CEDULA YA ESTA REGISTRADO</b>';
                
$errflag = true;
            }
            @
mysql_free_result($result);
        }
        else {
            die(
"Query failed");
        }
    }
    
    
//If there are input validations, redirect back to the registration form
    
if($errflag) {
        
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
        
session_write_close();
        
header("location: ../crear.php");
        exit();
    }

    
//Create INSERT query
    
$qry = "INSERT INTO datos_stands (empresa, estado, ciudad, nombres, apellidos, cedula1, cedula2, telefono, login, passwd, email, fecha) VALUES('$empresa','$estado','$ciudad','$nombres','$apellidos','$cedula1','$cedula2','$telefono','$login','".md5($_POST['password'])."','$email','".date("Y-m-d")."')";
    
$result = @mysql_query($qry);
    
    
//Check whether the query was successful or not
    
if($result) {
        
header("location: ../listo.php");
        exit();
    }else {
        die(
"Query failed");
    }
?>