Hi. i have this page in ASP that pulls an entered postcode and displays the apropriate details for that area and i need to translate it into PHP. can anyone help?
Im using a MySQL database.thank you for any help that you can give, much appreciated.
Function RemoveWhiteSpac e(strText) 'function to remove white spaces from post code
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "\s+"
RegEx.Multiline = True
RegEx.Global = True
strText = RegEx.Replace(s trText, "")
RemoveWhiteSpac e = strText
End Function
Dim nptCode, nptDistrict, noVals, origPostCode
origPostCode = Request.Form("p ostcode") 'do not alter this value
If (origPostCode <> "") Then 'we've come from the postcode search page
Dim cleanPostCode, wiltsCode
wiltsCode=False 'is it a wiltshire post code (see select statement)
cleanPostCode = UCase(RemoveWhi teSpace(origPos tCode))
Select Case Left(cleanPostC ode,2)
Case "BA", "SN", "SP", "GL", "RG"
wiltsCode=True
Case Else
Response.Redire ct("postcodesea rch.asp?e=nw&pc ode="&Request.F orm("postcode") &"")'go to post code error page with url extention (nw: not wiltshire)
End Select
If(wiltsCode)Th en
Dim rs_pcode
Dim rs_pcode_cmd
Dim rs_pcode_numRow s
Set rs_pcode_cmd = Server.CreateOb ject ("ADODB.Command ")
rs_pcode_cmd.Ac tiveConnection = MM_maincms_STRI NG
rs_pcode_cmd.Co mmandText = "SELECT npt_code, dis_name FROM q_npt_pcodes WHERE UCASE(pc_postco de) = ?"
rs_pcode_cmd.Pr epared = true
rs_pcode_cmd.Pa rameters.Append rs_pcode_cmd.Cr eateParameter(" param1", 200, 1, 10, cleanPostCode) ' adVarChar
Set rs_pcode = rs_pcode_cmd.Ex ecute
rs_pcode_numRow s = 0
If(rs_pcode.BOF OR rs_pcode.EOF)Th en
Response.Redire ct("postcodesea rch.asp?e=nf&pc ode="&Request.F orm("postcode") &"")'go to post code error page with url extention (nf: not found)
Else
nptCode=(rs_pco de.Fields.Item( "npt_code").Val ue)
nptDistrict=(rs _pcode.Fields.I tem("dis_name") .Value)
Dim MM_editCmd
Set MM_editCmd = Server.CreateOb ject ("ADODB.Command ")
MM_editCmd.Acti veConnection = MM_maincms_STRI NG
MM_editCmd.Comm andText = "INSERT INTO t_pcode_searche s (pcsearch_pc, pcsearch_outcom e, pcsearch_stamp, pcsearch_ip) VALUES (?,?,?,?)"
MM_editCmd.Prep ared = true
MM_editCmd.Para meters.Append MM_editCmd.Crea teParameter("pa ram1", 202, 1, 10, Request.Form("p ostcode")) ' adVarWChar
MM_editCmd.Para meters.Append MM_editCmd.Crea teParameter("pa ram2", 202, 1, 10, "ok") ' adVarWChar
MM_editCmd.Para meters.Append MM_editCmd.Crea teParameter("pa ram3", 135, 1, 50, Now()) ' date
MM_editCmd.Para meters.Append MM_editCmd.Crea teParameter("pa ram4", 202, 1, 50, Request.ServerV ariables("REMOT E_ADDR")) ' adVarWChar
MM_editCmd.Exec ute
MM_editCmd.Acti veConnection.Cl ose
End If
End If
Else ' we've come from the map page
'get url params
nptCode=UCase(R equest.QueryStr ing("id"))
nptDistrict=LCa se(Request.Quer yString("distri ct"))
'set district to correct value
Select Case nptDistrict
Case "salisbury"
nptDistrict="Sa lisbury"
Case "swindon"
nptDistrict="Sw indon"
Case "nwilts"
nptDistrict="No rth Wiltshire"
Case "wwilts"
nptDistrict="We st Wiltshire"
Case "kennet"
nptDistrict="Ke nnet"
Case Else
nptDistrict=""
End Select
End If
'set variable to check we have everything we need (used later)
If (nptCode="" Or nptDistrict="") Then
novals=True
End If
Dim xmlDoc
Set xmlDoc=Server.C reateObject("Mi crosoft.XMLDOM" )
xmlDoc.async=fa lse
xmlDoc.load(Ser ver.MapPath("xm l/nptdata.xml"))
xmlDoc.setPrope rty "SelectionLangu age", "XPath"
If xmlDoc.parseErr or.errorcode<>0 then
Response.Write( xmlDoc.parseErr or.errorcode)
Response.Write( "</br>Error processing xml file")
End If
nodepath="/NPTInfo/District[@DistrictName=' "&nptDistrict&" ']/NPT[@NPTCode='"&npt Code&"']"
%>
Im using a MySQL database.thank you for any help that you can give, much appreciated.
Function RemoveWhiteSpac e(strText) 'function to remove white spaces from post code
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "\s+"
RegEx.Multiline = True
RegEx.Global = True
strText = RegEx.Replace(s trText, "")
RemoveWhiteSpac e = strText
End Function
Dim nptCode, nptDistrict, noVals, origPostCode
origPostCode = Request.Form("p ostcode") 'do not alter this value
If (origPostCode <> "") Then 'we've come from the postcode search page
Dim cleanPostCode, wiltsCode
wiltsCode=False 'is it a wiltshire post code (see select statement)
cleanPostCode = UCase(RemoveWhi teSpace(origPos tCode))
Select Case Left(cleanPostC ode,2)
Case "BA", "SN", "SP", "GL", "RG"
wiltsCode=True
Case Else
Response.Redire ct("postcodesea rch.asp?e=nw&pc ode="&Request.F orm("postcode") &"")'go to post code error page with url extention (nw: not wiltshire)
End Select
If(wiltsCode)Th en
Dim rs_pcode
Dim rs_pcode_cmd
Dim rs_pcode_numRow s
Set rs_pcode_cmd = Server.CreateOb ject ("ADODB.Command ")
rs_pcode_cmd.Ac tiveConnection = MM_maincms_STRI NG
rs_pcode_cmd.Co mmandText = "SELECT npt_code, dis_name FROM q_npt_pcodes WHERE UCASE(pc_postco de) = ?"
rs_pcode_cmd.Pr epared = true
rs_pcode_cmd.Pa rameters.Append rs_pcode_cmd.Cr eateParameter(" param1", 200, 1, 10, cleanPostCode) ' adVarChar
Set rs_pcode = rs_pcode_cmd.Ex ecute
rs_pcode_numRow s = 0
If(rs_pcode.BOF OR rs_pcode.EOF)Th en
Response.Redire ct("postcodesea rch.asp?e=nf&pc ode="&Request.F orm("postcode") &"")'go to post code error page with url extention (nf: not found)
Else
nptCode=(rs_pco de.Fields.Item( "npt_code").Val ue)
nptDistrict=(rs _pcode.Fields.I tem("dis_name") .Value)
Dim MM_editCmd
Set MM_editCmd = Server.CreateOb ject ("ADODB.Command ")
MM_editCmd.Acti veConnection = MM_maincms_STRI NG
MM_editCmd.Comm andText = "INSERT INTO t_pcode_searche s (pcsearch_pc, pcsearch_outcom e, pcsearch_stamp, pcsearch_ip) VALUES (?,?,?,?)"
MM_editCmd.Prep ared = true
MM_editCmd.Para meters.Append MM_editCmd.Crea teParameter("pa ram1", 202, 1, 10, Request.Form("p ostcode")) ' adVarWChar
MM_editCmd.Para meters.Append MM_editCmd.Crea teParameter("pa ram2", 202, 1, 10, "ok") ' adVarWChar
MM_editCmd.Para meters.Append MM_editCmd.Crea teParameter("pa ram3", 135, 1, 50, Now()) ' date
MM_editCmd.Para meters.Append MM_editCmd.Crea teParameter("pa ram4", 202, 1, 50, Request.ServerV ariables("REMOT E_ADDR")) ' adVarWChar
MM_editCmd.Exec ute
MM_editCmd.Acti veConnection.Cl ose
End If
End If
Else ' we've come from the map page
'get url params
nptCode=UCase(R equest.QueryStr ing("id"))
nptDistrict=LCa se(Request.Quer yString("distri ct"))
'set district to correct value
Select Case nptDistrict
Case "salisbury"
nptDistrict="Sa lisbury"
Case "swindon"
nptDistrict="Sw indon"
Case "nwilts"
nptDistrict="No rth Wiltshire"
Case "wwilts"
nptDistrict="We st Wiltshire"
Case "kennet"
nptDistrict="Ke nnet"
Case Else
nptDistrict=""
End Select
End If
'set variable to check we have everything we need (used later)
If (nptCode="" Or nptDistrict="") Then
novals=True
End If
Dim xmlDoc
Set xmlDoc=Server.C reateObject("Mi crosoft.XMLDOM" )
xmlDoc.async=fa lse
xmlDoc.load(Ser ver.MapPath("xm l/nptdata.xml"))
xmlDoc.setPrope rty "SelectionLangu age", "XPath"
If xmlDoc.parseErr or.errorcode<>0 then
Response.Write( xmlDoc.parseErr or.errorcode)
Response.Write( "</br>Error processing xml file")
End If
nodepath="/NPTInfo/District[@DistrictName=' "&nptDistrict&" ']/NPT[@NPTCode='"&npt Code&"']"
%>
Comment