Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Script works online, but not locally??

Posted by Chris_Isaac (Chris Isaac), 4 February 2004
Hi

I have a script which can perform a search on Post Code, Name or Town.  The script is up and running on line and works fine.  I have set up the same database and script on my local machine for test purposes, but now the town search doesn't work, where the Post Code and Name does.  

I think I've narrowed it down to the segment below, can you see anything which may not cause the town search to work??

Code:
if ($next == 2) {
if (($county) or ($name)){
     $reports=1;}

     $town=addslashes($_GET[town]);
     $county =addslashes($_GET[county]);
     $name=addslashes($_GET[name]);
     sql_connect();
     print"$town, $county<br>";#  This does print out the correct town and county values
     $fullrep = "Alternative searches ...<br>";

     for ($i=0; $i<count($reports); $i++) {
     $filter = $searches[$i];
     
     if ($incode) {print"pcode bit working";#this print statement does work too
     $q = "Select * from hotel,locations where hotel.location = locations.id      and postcode rlike \"$filter\" order by active DESC, rand()";
           }
           elseif ($town and $county) {print"$town, $county town and county bit working";#this print statement doesn't work
     $q = "Select * from hotel,locations where hotel.location = locations.id      and town rlike \"$town\" and county rlike \"$county\" order by active DESC, rand()";
           }
           elseif ($name and $town) {print"$name, $town  town and name";#this print statement does work
     $q = "Select * from hotel,locations where hotel.location = locations.id      and hotel.name rlike \"$name\" and locations.town rlike \"$town\" order by active DESC, rand()";
           }
           else {
                 print "<br>Sorry, an error has occured, please go back and try again.<br>";
           }




Posted by admin (Graham Ellis), 4 February 2004
So .. can I clarify / ask...

a) The problem is NOT in the SQL but in the conditional test??
b) Where you say "does not work", do you mean that it prints nothing, or it prints the wrong message (such as the "Sorry" that's there on the else clause?).  It doesn't print out "pcode bit working" by any chance does it I could explain that one  

Posted by Chris_Isaac (Chris Isaac), 5 February 2004
"doesn't work" doesn't give a lot of information does it

When you do a search on town, it does bring up the list of options, eg, if you did a search on Newport it would give you a list like:

Newport, Gwent
Newport, IOW
etc, etc, etc

The above are hyperlinks which would then list all establishments in Newport, Gwent or whatever.  This is where it fail, it doesn't list any establishment at all, but if I search on postcode it does, and again you can search on name and thats fine too.  

All I did when I installed it locally was to change the paths to the local machine, I would have thought if this was wrong none of the searches would work.

Any thoughts?

Posted by admin (Graham Ellis), 5 February 2004
You've still not told me which (if any) of those print statements came out on the failed runs.   I'm suspecting a differing PHP version / setting of register_globals between the servers, as I've noticed that $incode isn't copied out of $_GET like the other variables are ...

Posted by Chris_Isaac (Chris Isaac), 5 February 2004
Sorry, it is in the code above, but not very clear:

9 line down prints out ok:
Code:
 
print"$town, $county<br>";#  This does print out the correct town and county values


Line 15, 1st test prints out ok:

Code:
if ($incode) {print"pcode bit working";#this print statement does work too


line 23 prints ok :

Code:
elseif ($name and $town) {print"$name, $town  town and name";#this print statement does work


The only line that doesn't print is line 19 :

Code:
elseif ($town and $county) {print"$town, $county town and county bit working";#this print statement doesn't work


I'll have a look at the global varibles when in work tomorrow and see if I can spot anything.

Thanks,
Chris

Posted by admin (Graham Ellis), 5 February 2004
Ah - sorry - I had read those comments differently.  Then it's got a true value that perhaps it shouldn't have in $incode on one machine, but not on the other?  Once a condition in an if... elseif ... else sequence is matched, it won't try others.  So as soon as it finds a postcode, it ignores the town it was given as that's a lower precendence operator.

Is the script triggered by the same referer page on both machines?  Does one trigger form include an incode entry and the other not?  Another possibility for you to look at.

Posted by Chris_Isaac (Chris Isaac), 5 February 2004
Its all triggered from the same script, whats confusing me is that the postcode search works, and so does the name, its just the town search that has the problem.

I've tested that the varibles are being populated with the correct values, strange.

I'll sleep on it and has a look at the register_globals see if that throws any light on it.

Cheers.

Posted by Chris_Isaac (Chris Isaac), 9 February 2004
update: I've now installed the scripts on my local machine at home as well and it is coming up with the same problem.  

I had a look at the global varibles on my local machine as well as the remote machine (where the scripts work correctly).  There is an entry called varibles_order, which on my local machine is set to EGPCS, but on the remote machine is set to NO VALUE.  Could this be it?   I've had a quick look at the others, some others do differ but I think this is due to my local machine running Win XP and the remote running FreeBSD.

Would any other varibles have this effect on a script?

Also just noticed my local machine is running 2.0.48 and the remote is running 1.3.28

Thanks in advance.

Posted by admin (Graham Ellis), 9 February 2004
Suggestion - try printing out the variables that are concerned with the tests in the problem area rather than just "I am here" messages.  My conjecture is that at least one of your variables is not being collected from $_GET and so you're prone to server configuration; I couldn't see where $incode came from in the snippet of code you posted.  The version number of Apache won't effect you so much as the version number of PHP.

The register_globals setting needs to be on before the variables_order has any effect, but do check $incode first as outlined above.  

Posted by Chris_Isaac (Chris Isaac), 9 February 2004
Thank you it was the register_globals, it was turned off, I turned it on and it works fine.

I did notice in the php.ini file that it says you should try to keep this feature turned off, for security.  Obviously on my local macine for testing it doesn't matter, but if I did need/want to keep it turned off, how could I have got around it?  

Thanks again.

Posted by admin (Graham Ellis), 9 February 2004
You should not rely on form / environment / cookie / server variables turning up in your code in variables with the same names as the form / environment / cookie / server field.  Instead, you should always use $_GET $_POST $_REQUEST $_COOKIE $_ENV and $_SERVER as appropriate.  You are using $_GET already for some variables, but clearly not consistently - otherwise changing the register_globals setting wouldn't have made any difference  

Posted by Chris_Isaac (Chris Isaac), 9 February 2004
What confuses me is I thought I was using $_GET, specially on the 2 varibles I was having trouble with:

Code:
$town=addslashes($_GET[town]);
$county =addslashes($_GET[county]);


$incode doesn't in the code you can see I admit, but $incode isn't causing a problem anyway.

Confused, but happy its working, thanks for your help



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho