Jump to content


Photo

$_GET[] not working properly


  • Please log in to reply
21 replies to this topic

#1 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 22 May 2006 - 08:24 PM

okay so in one page I have a script that looks something like this:
<a href='http://mysite.com/members/upload/files/filepage.htm?id=$fileid'>$filename</a>

And so when the user clicks the link it goes to:
[a href=\"http://mysite.com/members/upload/files/filepage.htm?id=3\" target=\"_blank\"]http://mysite.com/members/upload/files/filepage.htm?id=3[/a]

And filpage.htm contains a line that looks like this to get the value of 'id'
$id = $_GET['id'];
$sql = mysql_query("SELECT * FROM user_files WHERE file_id='$id'") or die ('Unknown file ID');

I am using PHPMyAdmin so I know that there is a place where file_id inside of user_files is equal to 3. Unfortunately I keep getting the die command 'Unknown file ID'. So, I am thinking that $_GET['id']; is not actually returning the value stored in the URL which is 3

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 22 May 2006 - 08:31 PM

filepage.htm? Unless you have made some changes to your server configuration, the php code in the .htm file is not going to be executed.
Legend has it that reading the manual never killed anyone.
My site

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 22 May 2006 - 08:39 PM

well he says he keeps getting the die message, so he must have it set to parse the php.. replace your die command with this:

$sql = mysql_query("SELECT * FROM user_files WHERE file_id='$id'") or die (mysql_error());

and post what the error says
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 22 May 2006 - 08:48 PM

woops...sorry. I have a line in filepage.htm like this:
<?php include('http://mysite.com/filepage.php'); ?>

and then the $_GET code is in the filepage.php file

Crayon_violet: I will try what you suggested and repost the error.



This time I got no error at all. Nothing showed up whatsoever, and I know that there is information in that row on my database.

Here is the filepage.php coding
<?php
$name="";
$lock="";
$database="";

$id = @$_GET['id'];

mysql_connect("",$name,$lock);
@mysql_select_db($database) or die( "Unable to select database");
$sql = mysql_query("SELECT * FROM user_files WHERE file_id='$id'") or die or die (mysql_error());
$info = mysql_fetch_array( $sql );
$content = $info['file_desc'];
$thumburl = $info['file_pic'];


if ($content='') 
   {echo "The user has not supplied a description for this file"; }
 else
   {echo "$content";}
?>


#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 22 May 2006 - 09:38 PM

you aren't getting any error messages cuz you don't have anything reporting them:

mysql_connect("",$name,$lock);

you probably need to put something like "localhost" in that first argument, and also throw in the mysql_error in there too:

mysql_connect("localhost",$name,$lock) or die(mysql_error();

... unless you took that out for posting purposes...

and this:

$sql = mysql_query("SELECT * FROM user_files WHERE file_id='$id'") or die or die (mysql_error());

should really be this:

$sql = mysql_query("SELECT * FROM user_files WHERE file_id='$id'") or die(mysql_error());

(you have 2 "or die" in there)

also try echoing $id after you set it:

$id = $_GET['id'];
echo $id;

see if it's printing out the id. maybe the id is not being passed, so nothing is being selected.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 23 May 2006 - 01:21 AM

Alright I played around with the code some and here's what I have (filepage.php):
<?php
$name="";
$lock="";
$database="";

$id = @$_GET['id'];

echo "$id";

mysql_connect("",$name,$lock) or die(mysql_error());
@mysql_select_db($database) or die( "Unable to select database");
$sql = "SELECT * FROM user_files WHERE file_id='$id'";
$query = mysql_query($sql);
$info = mysql_fetch_array($query);
$content = $info['file_desc'];
$thumburl = $info['file_pic'];


if ($content='0') 
   {echo "The user has not supplied a description for this file"; }
 else
   {echo "$content";}
?>

It is displaying 0 which I believe is the echoed value of $id. So apparently it is not being passed. How can I fix this problem?


#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 23 May 2006 - 01:36 AM

what is that @ for in front of the $_GET? i've never seen that before... take it out? that's supposed to suppress errors for like, queries and stuff. i don't think you are supposed to use that on variables...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#8 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 23 May 2006 - 01:39 AM

Take note of the help you've had from Crayon Violent and add some error and debugging displays. And remove the @ symbols. Try this - with your db information used - and uploaded to your server, and tell us what actually happens:

<?php
$name=""; // edit to suit
$lock=""; // edit to suit
$database=""; // edit to suit
$id = $_GET['id'];

echo "The value of id is ". $id. "<br/>";

mysql_connect("localhost",$name,$lock) or die(mysql_error());
mysql_select_db($database) or die( "Unable to select database");
$sql = "SELECT * FROM user_files WHERE file_id='$id'";
$query = mysql_query($sql) or die("Error: ". mysql_error(). " with query ". $sql);
$info = mysql_fetch_array($query);
$content = $info['file_desc'];
$thumburl = $info['file_pic'];


if ($content='')
   {echo "The user has not supplied a description for this file"; }
else
   {echo $content;}
?>

Legend has it that reading the manual never killed anyone.
My site

#9 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 23 May 2006 - 01:44 AM

Wow, this is really starting to frustrate me. I put exactly what you have in there Andy B. (except for the db info which I added in there) and it returned simply this:
"The value of id is "

#10 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 23 May 2006 - 01:48 AM

No sql error? Right?

I assume you're not calling that script in isolation (which would give no value for id), but getting it to run by clicking a link like:
<a href='filepage.php?id=2'>image 2</a>

Legend has it that reading the manual never killed anyone.
My site

#11 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 23 May 2006 - 01:54 AM

Yea it comes from a link. I have a list of files uploaded, where each file's info is stored in a db and on a page filelist.htm I display all the uploaded files. Well, I want a description page for each file so I did this:
echo"<a href='http://mysite.com/members/upload/files/filepage.htm?id=$fileid'>$filename</a>";
and when the user clicks on the link it will send them to [a href=\"http://mysite.com/members/upload/files/filepage.htm?id=3\" target=\"_blank\"]http://mysite.com/members/upload/files/filepage.htm?id=3[/a] (in this example).

#12 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 23 May 2006 - 01:57 AM

what are you seeing in the address bar?

http:://mysite.com/members/upload/files/filepage.htm?id=2

or

[a href=\"http://mysite.com/members/upload/files/filepage.htm?id=\" target=\"_blank\"]http://mysite.com/members/upload/files/filepage.htm?id=[/a]

try typing in the address by passing the var manually and see if your script works then

I see this from your first post

<a href='http://mysite.com/members/upload/files/filepage.htm?id=$fileid'>$filename</a>

which is probably your problem

try

<a href='http://mysite.com/me...ilepage.htm?id=' . $fileid . '>$filename</a>

or

<a href="http://mysite.com/members/upload/files/filepage.htm?id=$fileid">$filename</a>

note: double quotes and not single quotes above

I would like to see how your passing the id to the url, typing it in manually would narrow down the problem




:: gucci.com ::
:: blockbuster.com ::

--------------------

#13 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 23 May 2006 - 01:59 AM

I dont see how that would be the problem, the description page URL looks like this:
[a href=\"http://mysite.com/members/upload/files/filepage.htm?id=3\" target=\"_blank\"]http://mysite.com/members/upl...lepage.htm?id=3[/a] not
[a href=\"http://mysite.com/members/upload/files/filepage.htm?id=\" target=\"_blank\"]http://mysite.com/members/upl...ilepage.htm?id=[/a]

#14 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 23 May 2006 - 03:41 AM

dude you're missing the point. reread the previous post. manually type the url with the id=3 into your address bar and see if it passes.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#15 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 23 May 2006 - 05:28 AM

Hello,

I think the problem is with your include in filepage.htm

<?php include('http://mysite.com/filepage.php'); ?>

u r using URL to include....that can create problems passing the $_GET variable.Try following solutions:

1) Use relative path to include

<?php include('filepage.php'); ?>

OR

2) Pass the id to included file like this


<?php include('http://mysite.com/filepage.php?id='.$_GET['id']); ?>

hth
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#16 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 23 May 2006 - 06:04 PM

Crayon Violent: No, it still doesn't work.
I am going to try samshell's suggestion as I think it should work...I will edit later if the problem is still not solved

#17 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 23 May 2006 - 06:23 PM

alright samshell's idea has passed the value of ID onto the script so it works now, thx. The only problem is that it is still not returning the value of $content from the database.

Here is the column info for file_desc:
type: varchar
maxlength: 100
null: no

Here is the specific info for the entry with file_id equal to 3:
file_id: 3
file_name: ag5.png
file_size: 34394
file_type: Images
file_path: ...
file_creator: webdogjcn
file_desc: This is the default logo for the Alternative Gaming Website. Copyright 2006. All rights reserved.

It is returning this error:
The value of id is 3
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''user_files' WHERE file_id='3'' at line 1 with query SELECT * FROM user_files WHERE file_id='3'

$content=mysql_query("SELECT 'file_desc' FROM 'user_files' WHERE file_id='$id'") or die("Error: ". mysql_error(). " with query ". $sql);

The $sql is where I ran the query earlier just w/o the SELECT 'file_desc' aprt and just SELECT * (I did that for different reasons as I was trying to find a way to get this working).

n/m I took out the single quotes ('.') around the file_desc and user files. However I now just get "The value of id is 3" and it never displays the text stored in file_desc

#18 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 23 May 2006 - 09:33 PM

$content=mysql_query("SELECT 'file_desc' FROM 'user_files' WHERE file_id='$id'") or die("Error: ". mysql_error(). " with query ". $sql);
Humor me. Use the code I posted a few posts back instead of your version of it.
Legend has it that reading the manual never killed anyone.
My site

#19 mjozwiak

mjozwiak
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 May 2006 - 09:42 PM

hate to ask, but check if registared globals are on in your php.ini file

#20 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 24 May 2006 - 06:19 PM

Alright, thanks for all the help, but I managed to figure it out by myself. I have a new problem, shouldn't be as big of a deal.....
if ($getrating < 6 || $getrating > 0)
{
 $numrates ++; //Adds one to the total number of times this file has been rated
 $ccc = $ratesum; //Used to update the db below
 $ratesum += $getrating; //adds the user's own rating to the total
 $ratesum /= $numrates; //find the average

$sqlquery = "UPDATE user_files SET file_rates='$numrates',file_ratesum='$ccc',file_rating='$ratesum' WHERE file_id='$id'";
mysql_query($sqlquery) or die("Error: ". mysql_error(). " with query ". $sqlquery);
}
$getrating come from $_GET[]. This script is used to rate a file.

Okay so I want to find the average of all the ratings that have been made on the file so, everytime I rate the file it takes the # (1-5) (found in $getrating) and adds it to the total then takes that number and divides it by the times teh file has been rated.

PROBLEM: The only part that gets updated in the db is the file_rates nothing else.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users