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 RemoveWhiteSpace(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(strText, "")
RemoveWhiteSpace = strText
End Function
Dim nptCode, nptDistrict, noVals, origPostCode
origPostCode = Request.Form("postcode") '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(RemoveWhiteSpace(origPostCode))
Select Case Left(cleanPostCode,2)
Case "BA", "SN", "SP", "GL", "RG"
wiltsCode=True
Case Else
Response.Redirect("postcodesearch.asp?e=nw&pcode=" &Request.Form("postcode")&"")'go to post code error page with url extention (nw: not wiltshire)
End Select
If(wiltsCode)Then
Dim rs_pcode
Dim rs_pcode_cmd
Dim rs_pcode_numRows
Set rs_pcode_cmd = Server.CreateObject ("ADODB.Command")
rs_pcode_cmd.ActiveConnection = MM_maincms_STRING
rs_pcode_cmd.CommandText = "SELECT npt_code, dis_name FROM q_npt_pcodes WHERE UCASE(pc_postcode) = ?"
rs_pcode_cmd.Prepared = true
rs_pcode_cmd.Parameters.Append rs_pcode_cmd.CreateParameter("param1", 200, 1, 10, cleanPostCode) ' adVarChar
Set rs_pcode = rs_pcode_cmd.Execute
rs_pcode_numRows = 0
If(rs_pcode.BOF OR rs_pcode.EOF)Then
Response.Redirect("postcodesearch.asp?e=nf&pcode=" &Request.Form("postcode")&"")'go to post code error page with url extention (nf: not found)
Else
nptCode=(rs_pcode.Fields.Item("npt_code").Value)
nptDistrict=(rs_pcode.Fields.Item("dis_name").Valu e)
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_maincms_STRING
MM_editCmd.CommandText = "INSERT INTO t_pcode_searches (pcsearch_pc, pcsearch_outcome, pcsearch_stamp, pcsearch_ip) VALUES (?,?,?,?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 10, Request.Form("postcode")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 10, "ok") ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 135, 1, 50, Now()) ' date
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 202, 1, 50, Request.ServerVariables("REMOTE_ADDR")) ' adVarWChar
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
End If
Else ' we've come from the map page
'get url params
nptCode=UCase(Request.QueryString("id"))
nptDistrict=LCase(Request.QueryString("district"))
'set district to correct value
Select Case nptDistrict
Case "salisbury"
nptDistrict="Salisbury"
Case "swindon"
nptDistrict="Swindon"
Case "nwilts"
nptDistrict="North Wiltshire"
Case "wwilts"
nptDistrict="West Wiltshire"
Case "kennet"
nptDistrict="Kennet"
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.CreateObject("Microsoft.XMLDOM")
xmlDoc.async=false
xmlDoc.load(Server.MapPath("xml/nptdata.xml"))
xmlDoc.setProperty "SelectionLanguage", "XPath"
If xmlDoc.parseError.errorcode<>0 then
Response.Write(xmlDoc.parseError.errorcode)
Response.Write("</br>Error processing xml file")
End If
nodepath="/NPTInfo/District[@DistrictName='"&nptDistrict&"']/NPT[@NPTCode='"&nptCode&"']"
%>
17 1440
Well, as rule goes, will we never just hand out code - feels like I'm saying this alot recently, and others, too. Anyway, what I can do is: refer you to some tutorials on mysql/php; but before that you might want to actually learn PHP.
I hope all goes well in your project.
ps. When you've shown some initiative and given us a show of how you'v had a go at this yourself, we'll be glad to help more!
pss. When posting code in the forum - ASP in this case - wrap it in [code] tags. Makes it alot easier to read.
Sorry, i was hoping someone could translate it and then i could compare it to my attempt. here is my attempt, would you be able to take a look please?
[HTML]mysql_select_db($database_wpolconn, $wpolconn);
$query_rs_pcode = "SELECT npt_code, dis_name FROM q_npt_pcodes ";
$rs_pcode = mysql_query($query_rs_pcode, $wpolconn) or die(mysql_error());
$row_rs_pcode = mysql_fetch_assoc($rs_pcode);
$totalRows_rs_pcode = mysql_num_rows($rs_pcode);
?>
<?
function removeWhiteSpace($strText) { return preg_replace('~\s+~', '', $strText);} //function to remove white spaces from post code
$nptCode, $nptDistrict, $noVals, $origPostCode
origPostCode = @$GET ["postcode"]; //do not alter this value
If ($origPostCode ! =""){ //we've come from the postcode search page
$cleanPostCode, $wiltsCode;
}
$wiltsCode="False"; //is it a wiltshire post code (see switch statement )
$cleanPostCode = ucwords($RemoveWhiteSpace($origPostCode));
switch substr($cleanPostCode,0, 2); {
case "BA", "SN", "SP", "GL", "RG";
$wiltsCode="True";
default
header("postcodesearch.asp?e=nw&pcode="& @$_GET("postcode")&"");//go to post code error page with url extention (nw: not wiltshire)
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
//get url params
$nptCode= ucword(@$_GET("id"));
$nptDistrict= lcword(@$_GET("district"));
//set district to correct value
switch ($nptDistrict){
case "salisbury":
$nptDistrict="Salisbury"
case "swindon":
$nptDistrict="Swindon"
case "nwilts":
$nptDistrict="North Wiltshire"
case "wwilts":
$nptDistrict="West Wiltshire"
case "kennet":
$nptDistrict="Kennet"
default
$nptDistrict=""
}
}
//set variable to check we have everything we need (used later)
If ($nptCode=="" Or $nptDistrict==""){
$novals="True";
}
$xmlDoc
//Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM") - not needed in PHP
//xmlDoc.async=false
//xmlDoc.load(Server.MapPath("xml/nptdata.xml"))
//xmlDoc.setProperty "SelectionLanguage", "XPath"
If $xmlDoc.parseError.errorcode<>0 {
echo "$xmlDoc.parseError.errorcode";
echo "</br>Error processing xml file";
}
nodepath="/NPTInfo/District[@DistrictName='"&nptDistrict&"']/NPT[@NPTCode='"&nptCode&"']"
%>
<?php
mysql_free_result($rs_pcode);
?>[/HTML]
Have you tried it yet? Does it work?
Yes i have tried it and unfortunatly it doesnt work.
Yes i have tried it and unfortunatly it doesnt work.
Give more details. Do you get an error message?
Ive made a few amends but still not working it gives the error Parse error: syntax error, unexpected '!' from this line:
[HTML]if ($origPostCode ! == ""){ //we've come from the postcode search page[/HTML]
i need the in there though because it is supposed to say is not equal to nothing.
[HTML]mysql_select_db($database_wpolconn, $wpolconn);
$query_rs_pcode = "SELECT npt_code, dis_name FROM q_npt_pcodes ";
$rs_pcode = mysql_query($query_rs_pcode, $wpolconn) or die(mysql_error());
$row_rs_pcode = mysql_fetch_assoc($rs_pcode);
$totalRows_rs_pcode = mysql_num_rows($rs_pcode);
?>
<?
function removeWhiteSpace($strText) { return preg_replace('~\s+~', '', $strText);} //function to remove white spaces from post code
$origPostCode = @$_GET ["postcode"]; //do not alter this value
if ($origPostCode ! == ""){ //we've come from the postcode search page
$wiltsCode="False"; //is it a wiltshire post code (see switch statement )
$cleanPostCode = ucwords($RemoveWhiteSpace($origPostCode));
switch substr($cleanPostCode,0, 2); {
case "BA", "SN", "SP", "GL", "RG";
$wiltsCode="True";
default
header("postcodesearch.asp?e=nw&pcode="& @$_GET("postcode")&"");//go to post code error page with url extention (nw: not wiltshire)
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
//get url params
$nptCode= ucword(@$_GET("id"));
$nptDistrict= lcword(@$_GET("district"));
//set district to correct value
switch ($nptDistrict){
case "salisbury":
$nptDistrict="Salisbury"
case "swindon":
$nptDistrict="Swindon"
case "nwilts":
$nptDistrict="North Wiltshire"
case "wwilts":
$nptDistrict="West Wiltshire"
case "kennet":
$nptDistrict="Kennet"
default
$nptDistrict=""
}
}
//set variable to check we have everything we need (used later)
if ($nptCode=="" Or $nptDistrict==""){
$novals="True";
}
$xmlDoc
//Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM") - not needed in PHP
//xmlDoc.async=false
//xmlDoc.load(Server.MapPath("xml/nptdata.xml"))
//xmlDoc.setProperty "SelectionLanguage", "XPath"
if $xmlDoc.parseError.errorcode<>0 {
echo "$xmlDoc.parseError.errorcode";
echo "</br>Error processing xml file";
}
nodepath="/NPTInfo/District[@DistrictName='"&nptDistrict&"']/NPT[@NPTCode='"&nptCode&"']"
%>
<?php
mysql_free_result($rs_pcode);
?>[/HTML]
I just tried it and it is still giving the same error.
I just tried it and it is still giving the same error.
Same error message on same line number?
!=
with one = sign.
!== would still work. It compares an exact match - type and value. It was the space that was causing the error.
That sorted it, thanks. now im getting Parse error: syntax error, unexpected T_STRING on line 21.
That sorted it, thanks. now im getting Parse error: syntax error, unexpected T_STRING on line 21.
I think your problem is here:
switch substr($cleanPostCode,0, 2); {
The semi colon isn't needed I believe, so try:
switch substr($cleanPostCode,0, 2) {
Just tried it, same error on the same line.
Just tried it, same error on the same line.
Change the switch statement to this, see if it helps. -
$pc = array("BA", "SN", "SP", "GL", "RG");
-
if( in_array ( substr ($cleanPostCode, 0, 2 ), $pc)
-
$wiltsCode="True";
-
else
-
# header...
-
Heya, SClarkstone.
Switch requires parenthesis. E.g., -
switch( substr($cleanPostCode,0, 2) )
-
{
-
Heya, SClarkstone.
Switch requires parenthesis. E.g., -
switch( substr($cleanPostCode,0, 2) )
-
{
-
Good spot!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: William C. White |
last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using
cURL? Our website is hosted on a shared drive and the webhost company
doesn't installed additional software (such as cURL)...
|
by: Albert Ahtenberg |
last post by:
Hello,
I don't know if it is only me but I was sure that header("Location:url")
redirects the browser instantly to URL, or at least stops the execution of
the code. But appearantely it continues...
|
by: James |
last post by:
Hi,
I have a form with 2 fields.
'A'
'B'
The user completes one of the fields and the form is submitted.
On the results page I want to run a query, but this will change
subject to which...
|
by: Ollivier Robert |
last post by:
Hello,
I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9
system. The link succeeds but everytime I try to run php, I get a SEGV from
inside the libcnltsh.so library.
...
|
by: Richard Galli |
last post by:
I want viewers to compare state laws on a single subject.
Imagine a three-column table with a drop-down box on the top. A viewer
selects a state from the list, and that state's text fills the...
|
by: Albert Ahtenberg |
last post by:
Hello,
I have two questions.
1. When the user presses the back button and returns to a form he filled
the form is reseted. How do I leave there the values he inserted?
2. When the...
|
by: inderjit S Gabrie |
last post by:
Hi all
Here is the scenerio ...is it possibly to do this...
i am getting valid course dates output on to a web which i have designed
....all is okay so far , look at the following web url
...
|
by: Jack |
last post by:
Hi All,
What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g.
select x from y where z=:parameter
Which in asp/jsp would be followed by some statements to bind a value...
|
by: Sandwick |
last post by:
I am trying to change the size of a drawing so they are all 3x3.
the script below is what i was trying to use to cut it in half ... I
get errors.
I can display the normal picture but not the...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |