0

I need to make a column in phpMyAdmin unique and optional at the same time.. This will be used in a registration form. The user is not required to provide this information but if they do, there cannot be another duplicate entry.

More Info:

I have a table called "client_order_number", in this table I will store the client's order number.. When the user fills out the form located in our frontend, this field should be optional (Not required) but if the user does provide this information, I need it to be unique meaning, if another user decides to provide this information as well he can't input the same exact client number as the previous user.

Here's a screenshot of my database:

Screenshot of my database structure

  • Unique columns can also be `NULL`. – Martin Sep 13 '21 at 01:20
  • What is your question, exactly? – Isaac Bennetch Sep 13 '21 at 01:23
  • @IsaacBennetch The questions is how do I make a column optional and unique at the same time in phpMyAdmin. The column "client_order_number" is optional (the user does not need to provide thus information on the form.) but it also needs to be a unique column. No 2 entries can be the same.. Right now, I keep getting an error saying my entry is duplicate but I left it blank. – Richard Rodgers Sep 13 '21 at 01:28
  • When we're helping you with these things, it's useful to know what you've tried already and what exactly hasn't worked. Please tell us the table structure; what index or keys have you defined, etc? It may be easiest to copy and paste the output of `show create table foo` in to your question (where foo is your table name, of course). It's working fine for me in my test so in order to know what you've done differently, we have to know what you've done :) – Isaac Bennetch Sep 13 '21 at 01:34
  • @IsaacBennetch You are 100% correct. I edited the post and provided more information. I hope this helps and sorry if I'm not being very clear.. I am a noob.. – Richard Rodgers Sep 13 '21 at 01:46
  • As the others have indicated, you'll want to allow NULL values. From the phpMyAdmin table structure page that you've used to post the screenshot, you can click on "Change" for "client_order_number" and about halfway across the page you'll see a checkbox for the NULL selector, which will be unchecked. If you check that, you'll be allowing NULL values, which is what you'll want to insert in your front end logic if the user doesn't provide the client order number. – Isaac Bennetch Sep 13 '21 at 02:19

0 Answers0