0

Hey got a big issue i need to resolve

if i have a table that records two distinct values entered by user.. NC001 OR TE001

Equipment_id | Serial | location
--------------------------------
NC001 |

if i have a php based form how can i tell it that if a user select NC or TE from a drop down box it automatically fills in the next field with

select MAX(`Equipment_ID`) FROM `asset_base` WHERE `Equipment_ID` LIKE '%NC%' +1

to increment the max NC upwards to add a new item without the user being able to overwrite the NC number..

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by smantscheff
0

This reeks like really bad table design.
You cannot do it dynamically in PHP in one form on one web page because PHP is a server language which does not work in the browser. You have to setup some javascript code in your page which alters the value of the NC/TE number field on change of the dropdown field.
But with that setup you're bound for trouble because you would have to lock the database for updates until the form is sent - otherwise you might end up with identical NC/TE numbers from different clients.
It's better to fill in the NC/TE number on database level in a trigger when the user data are stored and only then to display the auto-generated number to the user.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.