How to avoid mixing id in update statements?

Lets say I‘m having a list of adverts on one page. This list with my adverts comes from a Database:

table adverts:

  • id
  • id_customer

table customer:

  • id
  • name

now comes the point where I use two modal windows (modalupdateAdvert, modalupdateCustomer) on same page with each formupdate statements. Now it looks like its mixing up the „id“ from customer with the one from adverts and I‘m getting strange update results.

Now I have to say, that I‘m just querying * all (asterisk/joker query) from adverts and customers, so I have more flexibility later, instead of defining and giving each column of my query an alias.

That mixing with id‘s remembers me from my old times, when using dreamweaver back in 2002…

@ben How do you handle that uniqueness? I‘m using these modals and update statements on same page, cause its slim and later for translating it would be easier to manage just one file, instead of having each update forms on separate pages.

by the way I‘m using also a temporary variable to pass the id‘s to the modal forms.

Personally I identify IDs by name so I would have something like advertid and customerid rather than plain ID but you can also alias them in server connect or fully qualify the id with something like myconnection.query.id

3 Likes

I’d use Cookies and set on Click events for your id fields respectively (select the id value from the repeat). Then filter your updates using the Cookie value, then remove the Cookies on Success.

2 Likes

@dave you mean Variable? Im following the video from youtube with modal update. That multi episode tutorial from grocery store… forgot the name.

Or use a UID for the customer and set the Cookie to that UID for updates (or better still encrypt the Cookie or at least base64 encode it) to avoid any unnecessary adjustment of Cookie values…

I’d skip that step and just set a Cookie on click event then filter your update based on the Cookie value.

1 Like

this one : https://youtu.be/eGzsNj9eBW0

Learn to love your Cookies! :slight_smile:

2 Likes

Sorry but in my mind this is using cookies for the sake of it. I see no added value over using variables but do see an overhead in encrypting and setting a cookie.

Each to their own I suppose. If a Client wants Cookies they’ll get them, encrypted or otherwise. Sometimes my opinions are of no consequence…

Also the overhead is tiny on modern hardware… One of the servers I connect to has 6tb of memory others around the same. Encrypting a Cookie presents no issue at all.

most clients even dont understand what a cookie and what a computer is

1 Like

I do the same as what @Hyperbytes does, I always include the name of the table.

image
and
image

2 Likes

@ben okay I see youre including also tablename. I guess I‘ll change my whole database before starting with my project. Thanx alot but with that I wont mixup stuff and its clear then. Takes some tiny work more but better than the opposite and spending hours for finding whats wrong with ids from which table.

3 Likes