botshara Posted November 7, 2013 Share Posted November 7, 2013 (edited) 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 November 7, 2013 by Guest Link to comment
xXMADEXx Posted November 7, 2013 Share Posted November 7, 2013 number = exports.sql:query_insertid( "INSERT INTO phones VALUES ()" ); you didn't put anything in for 'VALUES.' Link to comment
botshara Posted November 9, 2013 Author Share Posted November 9, 2013 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now