<% Dim vendor, isprinter, ispc, ismachine vendor = Trim(Request.Form("vendor")) isprinter = Request.Form("isprinter") ispc = Request.Form("ispc") ismachine = Request.Form("ismachine") ' Validate If vendor = "" Then Response.Write("
Error: Manufacturer name is required.
") Response.Write("Go back") objConn.Close Response.End End If If Len(vendor) > 50 Then Response.Write("
Error: Manufacturer name too long.
") Response.Write("Go back") objConn.Close Response.End End If If isprinter <> "1" AND ispc <> "1" AND ismachine <> "1" Then Response.Write("
Error: Please select at least one category.
") Response.Write("Go back") objConn.Close Response.End End If ' Check if exists Dim checkSQL, rsCheck checkSQL = "SELECT COUNT(*) as cnt FROM vendors WHERE LOWER(vendor) = LOWER('" & Replace(vendor, "'", "''") & "')" Set rsCheck = objConn.Execute(checkSQL) If rsCheck("cnt") > 0 Then rsCheck.Close Response.Write("
Error: Manufacturer '" & Server.HTMLEncode(vendor) & "' already exists.
") Response.Write("Go back") objConn.Close Response.End End If rsCheck.Close ' Escape quotes vendor = Replace(vendor, "'", "''") ' Convert checkboxes Dim iPrint, iPC, iMach If isprinter = "1" Then iPrint = 1 Else iPrint = 0 If ispc = "1" Then iPC = 1 Else iPC = 0 If ismachine = "1" Then iMach = 1 Else iMach = 0 ' INSERT Dim vendorSQL vendorSQL = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) " & _ "VALUES ('" & vendor & "', 1, " & iPrint & ", " & iPC & ", " & iMach & ")" On Error Resume Next objConn.Execute vendorSQL If Err.Number <> 0 Then Response.Write("
Error: " & Err.Description & "
") Response.Write("Go back") objConn.Close Response.End End If Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid") Dim newVendorId newVendorId = rsCheck("newid") rsCheck.Close objConn.Close If newVendorId > 0 Then Response.Write("
Manufacturer added successfully!
") Response.Write("

Manufacturer '" & Server.HTMLEncode(Request.Form("vendor")) & "' has been added.

") Response.Write("

Add Another Manufacturer ") Response.Write("Add Model

") Else Response.Write("
Error: Manufacturer was not added.
") Response.Write("Go back") End If %>