Jump to content

phone number [error]


botshara

Recommended Posts

The error is at line 4 'end' expected

  
-- we need to export a function to generate a new (unused) phone number, really 
function createPhone( number ) 
    if not number then 
        number = exports.sql:query_insertid( "INSERT INTO phones VALUES ()" ); 
    else 
        -- we create a row for the one that didn't exist yet but where we have the number for. 
        while true do 
            attempts = attempts + 1 
            number = math.random(311111, attempts < 20 and 899999 or 8999999) 
                -- no current phones OR the new phone number is the new max. 
                end 
                return createPhone( ) 
                -- we have a phone number that's below the maximum 
                if not exports.sql:query_free( "INSERT INTO phones (phoneNumber) VALUES (" .. number .. ")" ) then 
                     -- if this fails, the phone number does exist 
                 
                    return false 
                end 
             
            else 
                -- number is too high, ignore 
                return false 
             
        else 
            return createPhone( ) 
     
      end 
    return number -- we don't want to return the MySQL error if that failed 
end 
  

Edited by Guest
Link to comment
number = exports.sql:query_insertid( "INSERT INTO phones VALUES ()" ); 

you didn't put anything in for 'VALUES.'

nop, it is correct if not number insert nothing.

something here is problem to close while or if's

   if not number then 
        number = exports.sql:query_insertid( "INSERT INTO phones VALUES ()" ); 
    else 
        -- we create a row for the one that didn't exist yet but where we have the number for. 
        while true do 
            attempts = attempts + 1 
            number = math.random(311111, attempts < 20 and 899999 or 8999999) 
                -- no current phones OR the new phone number is the new max. 
                end 
                return createPhone( ) 
                -- we have a phone number that's below the maximum 
                if not exports.sql:query_free( "INSERT INTO phones (phoneNumber) VALUES (" .. number .. ")" ) then 
                     -- if this fails, the phone number does exist 
                
                    return false 
                end 
            
            else 
                -- number is too high, ignore 
                return false 
            
        else 
            return createPhone( ) 
    
      end 
    return number -- we don't want to return the MySQL error if that failed 
end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...