ben_1uk Posted March 22, 2011 Share Posted March 22, 2011 Hello everyone, I have put together a HTML form in which data is being collected, then verified with a PHP script before being posted into a SQL database. Is there anyway I can auto assign a unique ID to a database entry other than the default auto increment ID field? I want to be able to assign random ID numbers to tickets for an event and was hoping that something could be achieved in SQL..? Many thanks, BB2011 Quote Link to comment https://forums.phpfreaks.com/topic/231373-sql-database-help/ Share on other sites More sharing options...
MrXHellboy Posted March 22, 2011 Share Posted March 22, 2011 Create a unique ID in PHP and put it into the DB. You can create a function with only numbers yourself, very simple. or something like a already existing function http://nl3.php.net/manual/en/function.uniqid.php Quote Link to comment https://forums.phpfreaks.com/topic/231373-sql-database-help/#findComment-1190761 Share on other sites More sharing options...
ben_1uk Posted March 22, 2011 Author Share Posted March 22, 2011 Thanks for that. I'm a bit of a PHP novice and wondered if you could show me an example of a simple PHP script that will generate an 8-digit unique ticket ID. Also, how would I post this into my existing SQL database? Thanks, BB2011 Quote Link to comment https://forums.phpfreaks.com/topic/231373-sql-database-help/#findComment-1190794 Share on other sites More sharing options...
ben_1uk Posted March 22, 2011 Author Share Posted March 22, 2011 I have found numerous PHP scripts that will generate a unique number I can use for Ticket_ID, but because the existing data in my database is being populated by a user via a HTML form, I don't see how I can incorporate the use of such a script to correctly allocate a unique ID against a new database entry. In other words, I cannot "post" the Ticket_ID to the database using the form so how would I go about posting this data? Is there a way this can be handled automatically by SQL? I've been reading alot about GUID's, but I'm not sure how to create one as I have not created the database using code. Quote Link to comment https://forums.phpfreaks.com/topic/231373-sql-database-help/#findComment-1190878 Share on other sites More sharing options...
jakebur01 Posted March 22, 2011 Share Posted March 22, 2011 If you are updating existing data, you probably could just add a column to the database and call it ticket_id and update the ticket id into that column. Just have php generate the unique number, have php check to be sure this number is not already being used, if so create another id, check again, then update the number into the column. If you could post your html form code and the php you are using to update or post, I might could help you better. Quote Link to comment https://forums.phpfreaks.com/topic/231373-sql-database-help/#findComment-1190942 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.