need some input
i know how to populate a php dropdown list from MSSQLServer Datebase and save the selected value in the datebase, but i want to add new dynamical entrys in the dropdown menu and save them into the database. Here is the code:
some help?
I would recommend doing all this in the SQL level, try this it is modified from a stored procedure I use in a similar fashion
Create Procedure [dbo].[MergeStatus](
@StatusID int,
@Status Varchar(8000)
)
AS
BEGIN
set nocount on;
Merge [Master.dbo.Status] as Target
using (select @StatusID As ID) As source
On
(Target.StatusID = source.ID)
When Matched Then
INSERT INTO Master.dbo.AllgemeineAngaben (StatusID) VALUES (@StatusID ) -- we have a match ID is Greater than 0 so insert into new tabke
When Not Matched Then
Insert (
@Status -- no match add new to Master.dbo.Status
)
Values(
@Status
);
IF @StatusID IS NULL or @StatusID = 0 -- our ID is not waht we expected so we need to insert
BEGIN
SET @Id = CAST(SCOPE_IDENTITY() as [int]);--getting ID od record we just inserted
INSERT INTO Master.dbo.AllgemeineAngaben (StatusID) VALUES (@StatusID )
END
END