Duplicate entires/aut-incrementing

Okay, so let’s just start up by saying that this is all dealing with $LicNo.
I am working on a website, that is connected to a database, written with PHP. I do not have access to edit anything in the MySQL database, only the PHP code. The website is a dog licensing system for the county. So what my boss would like to see, is any time the License Number($LicNo) is updated, it will auto increment by 100000 that way there will be no duplicates. I’ve tried everything I can think of, and am at a complete loss of what to do next. Can anyone out there help?

I don’t know why on earth you would increment something by 100,000 to prevent a duplicate when you could insert it with a timestamp as the licence:

//Insert to the database with a unique licence number
$statement = $dbconn->prepare("
INSERT INTO licences (name, pet_name, licence, start, end)
VALUES (:name, :pet_name, NOW(), :start, :end)
“:name” => $_POST[‘name’],
“:pet_name” => $_POST[‘pet_name’],
“:start” => $_POST[‘start’],
“:end” => $_POST[‘end’]


Sorry I threw out an insert, you wanted update but the theory is the same… The licence shouldn’t change if I’m thinking of it correctly? That’s the point of a licence, it’s unique to the user (note you could use the ID of the row as the licence as that’s always unique?) but NOW() will insert a timestamp. If you want something a little more ‘user friendly’ then you could convert a timestamp to MD5.

Alternatively, append an item in the database such as last name with user ID.

There are so many ways to create a unique identifier but even thinking about incrementing something by 100,000 proves that you’ve done it wrong in the first place.

Thank you, but the reason I was trying to increment it by that number is because it is was my boss told me he wanted done. I am extremely new to PHP but have a basic knowledge of programming.

Also, i’m having a hard time working with the code you sent, it just keeps breaking the webpage.

He may want it done, but if you want to do it properly, it shouldn’t need to be done in the first place.

You’ll have to see if someone else will help you out because I refuse to give bad advise.

That’s probably because you’re running PHP 5.2, probably running old mysql_query too.

The code I sent runs on PHP 5.4 – I decided to stop supporting lower versions of PHP as there’s no excuse for not keeping up with modern standards.

All I asked for was help, you didn’t have to be so negative about the way things are being done, hopefully somebody else reply, and at least be reasonable. Thanks anyways.

Sorry, don’t read my posts as negative. It is true that you should do it properly, correct? Also important to keep your software up-to-date in order to maintain the security and integrity of your data, correct? PHP5.4 handles arrays differently, so instead of:

e.g. in:

Your would have:

That is probably why it’s failing, but if you post the error, we can help further. Another reason it could be failing is because you’re not using PDO, again, posting the error will allow us to help you further.

Again, don’t read my posts as negative, I want to help, but won’t give you bad advise. That’s a good thing, right?

He probably wasn’t meaning to be very negative, this is just something developers have to deal with a lot. A customer (in this case your boss) wanting something done, and having an opinion about how it should be done. The problem with this is that you usually end up with an XY problem situation. http://mywiki.wooledge.org/XyProblem

Your question is actually an example of one of these. Your real problem is that the IDs aren’t unique, but instead you’re trying to solve your bosses “strange” incrementing IDs solution.

The real solution is to alter the table to have an auto incrementing id column. That way you don’t even have to submit an ID, you just submit the rest of the table data and mysql will in real time select the next available ID for you.

Please ask your boss to consider allowing you access to sql.

If all else fails, you need some kind of uuid system. But I have an iffy feeling the ID column is a integer field.

Could you run this query so we can see what kind of column we’re talking about? You have to change the two names to whatever you are using :slight_smile:


Sponsor our Newsletter | Privacy Policy | Terms of Service