SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    validation for users when sign up for event

    Hello All,

    I want to create php system that will validate when users
    register for the event today (for example), it will check in mysql database if
    they did not registered for this event before.
    Any suggestions welcome.
    Thanks !!

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You have two options.

    First is to group the unique fields UNIQUE in the table, so an insert attempt will fail.

    Second is to do a query to search the table for the specific data - if more than 0 rows are found, then the validation fails.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks,

    second option would be more reliable for us.
    do you have an example of code which I can implement?


    Thanks !!!

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, it would look something like this, assuming that the form names are the same as the table names (or a concatenation thereof):
    PHP Code:
    <?php
    function isUnique(){
        
    $uniqueFields func_get_args();
        
    $sql 'SELECT id FROM registered WHERE 1 = 1';
        foreach(
    $uniqueFields as $uniqueField){
            
    $sql .= " AND {$uniqueField} = '" mysql_real_escape_string($_POST[$uniqueField]) . "'";
        }
        
    $query mysql_query($sql);
        return (
    mysql_num_rows($query) < 1);
    }
    Example usage:
    PHP Code:
    if(!isUnique('name''telephone')){
        echo 
    'It seems you have already registered.';
    }else{
        
    // continue...

    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •