Is this a URL problem? or a MySQL problem? or browser?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mlkarie
Forum Newbie
Posts: 11
Joined: Tue Oct 12, 2004 6:53 am

Is this a URL problem? or a MySQL problem? or browser?

Post 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?
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Why dont you post the code you use to pull the records out of the database from page1.php.
mlkarie
Forum Newbie
Posts: 11
Joined: Tue Oct 12, 2004 6:53 am

Problems with PHP MySQL queries

Post 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”

?>


?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
mlkarie
Forum Newbie
Posts: 11
Joined: Tue Oct 12, 2004 6:53 am

Problem re variables from URL, Mysql query does not work

Post 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
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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?
Image Image
mlkarie
Forum Newbie
Posts: 11
Joined: Tue Oct 12, 2004 6:53 am

URL variables not working in MySQL query

Post 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&current=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?
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post 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.
mlkarie
Forum Newbie
Posts: 11
Joined: Tue Oct 12, 2004 6:53 am

URL variables not working in MySQL query

Post 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.
Post Reply