Page 1 of 1
Is this a URL problem? or a MySQL problem? or browser?
Posted: Thu Oct 21, 2004 2:55 am
by mlkarie
Problem description:
User types
page1.php?var1=shop&var2=sports
This URL sent from my own two computers works fine, MysQL query finds the appropriate record, and next page is displayed correctly.
On two computers in another office this works fine, but on three other computers in the same office, MySQL returns a result of 0 (i.e. $numrows = 0.) It seems that the word “shop”, which does exist in the database, is not passed through as “shop”.?
I had a similar problem with a different page from my own computer – MySQL query returns a 0 result. I then added a “dummy” variable to the URL
page1.php?var1=shop&var2=sports&hello=world
and MySQL found the correct record for shop.
Why did this dummy variable change the result?
In the PHP page, the variables are read from the URL by the $_GET method.
I have not used any urldecode/unescapes, etc, as all these URL variables are simple words without spaces, hyphens or anything strange.
Please could someone tell me what the problem is?
Posted: Thu Oct 21, 2004 3:16 am
by Wayne
Why dont you post the code you use to pull the records out of the database from page1.php.
Problems with PHP MySQL queries
Posted: Thu Oct 21, 2004 3:54 am
by mlkarie
Code: Select all
<?php
$shop = $_GET['shop'];
$sports = $_GET['sports'];
include("generalfiles/definitions.php");
include("generalfiles/connect2db.php");
$query2 = "SELECT * FROM dbtable WHERE shop = '$shop' AND sports = '$sports'";
$result2 = mysql_query($query2);
if (!$result2) {
$returnstring = "n=2&error=notfound&end=exit";
echo $returnstring;
exit;
} // no result
$numrows2 = mysql_num_rows($result2);
if ($numrows2 > 0) {
$row2 = mysql_fetch_assoc($result2);
$newsshop = $row2['filename'];
}
$navname = $newsshop."-navigation.swf"; //$newsshop contains the correct filename, for construction of the *-navigation file
include("shop-sub.html");
// in the file shop-sub.html there is an “echo $navname”
?>
?>
Posted: Thu Oct 21, 2004 5:52 pm
by feyd
$_GET['shop'] and $_GET['sports'] do not exist in your urls. 'shop' and 'sports' are the values of 'var1' and 'var2'. You have some seriously twisted systems if that code works with those urls.
Problem re variables from URL, Mysql query does not work
Posted: Fri Oct 22, 2004 2:26 am
by mlkarie
Oops, that mistake crept in when I changed some variable names for this post, as I did not want to use the originals
So, the URL changes to:
page1.php?shop=abc&sports=123
Posted: Fri Oct 22, 2004 2:31 am
by phice
Try:
Code: Select all
print "<pre>\n";
print_r ( $_GET );
print "</pre>\n";
to see what variables are sent through the URL (if any!). What version of PHP are you using on the server that isn't working?
URL variables not working in MySQL query
Posted: Fri Oct 22, 2004 4:21 am
by mlkarie
Not able to do the "print" of the $_GET variables right now, but just want to mention the following:
I had the same problem in another file which received only one variable from the URL. The actual value of the variable was 131.
In the PHP file I did "echo $id" after the $_GET statement, and before and after the query (showed up correctly as 131).
I also did an "echo $query" statement. This printed the exacty query, 100% correct, on the screen. However, the mysql query returns a 0 result, even though that id number does exist in the database.
The same query, typed into PHPMyAdmin's SQL window, ran correctly.
Then I did this: instead of "filename.php?id=131" I said "filename.php?id=131¤t=yes", where "current" is a dummy variable that is not used at all.
This "solved" the problem - the query now ran correctly.
So in my file, working with the shops and the sport, I also placed a dummy variable at the end of the URL. Everything works fine from my two computers, and from some computers in another office, but not on other computers in that office, even with the dummy variable of current=yes.
Why does the query work from 4 computers in two different cities, and not on 2 or 3 others in the second city? Is this a browser problem? Or is it a mysql database problem?
Posted: Fri Oct 22, 2004 9:46 am
by lostboy
It might be a caching problem. Where the page/url doesn't seem to change and therefore doesn't really make it back to the server. Try adding the current time to the end of the URL to force the browser to look for a new page each time.
URL variables not working in MySQL query
Posted: Mon Oct 25, 2004 1:36 pm
by mlkarie
Thanks for the reply. I'm unable to try this straight away (marking exam papers) so will try your suggestion in two days' time or so, and reply.