Current location: Hot Scripts Forums » Programming Languages » PHP » Passing a variable to another page


Passing a variable to another page

Reply
  #1 (permalink)  
Old 02-09-05, 04:50 PM
tapir tapir is offline
Newbie Coder
 
Join Date: Jan 2005
Location: UK
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Passing a variable to another page

Hi all, I'm hoping that someone can help me out (again!)
The project: A PHP contacts/address book.
page 1: search for a contact, page displays basic info, inlcuding a link to page 2 that will display full results for the selected contact.

The problem: Value does not appear to be passed from page 1 to page 2.

The link on page 1 opens page 2 correctly, but there are no details shown, just table headings. The value I wish to pass is 'UID' from the selected contact, so my link code on page 1 is:
PHP Code:

<a href="view2.php?UID=$UID"
Page 2 is using the following code to get the UID value:

PHP Code:

$UID=$_GET['UID']; 

The SQL is a simple
PHP Code:

$sql2="SELECT title, first_name, last_name FROM users where UID = '$UID' "

or die ("Could not execute select"); 
If I substitute $UID in the SQl for a known UID, the page displays the correct results.

Any thoughts on this please?

Thanks in advance

:t:
Reply With Quote
  #2 (permalink)  
Old 02-09-05, 06:28 PM
JBChris JBChris is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Just a thought: are you inside of a function when you're calling the SQL???
Reply With Quote
  #3 (permalink)  
Old 02-10-05, 04:11 AM
tapir tapir is offline
Newbie Coder
 
Join Date: Jan 2005
Location: UK
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by JBChris
Just a thought: are you inside of a function when you're calling the SQL???
Afraid not, the SQL is simply part of the whole PHP page, and not a function.
Reply With Quote
  #4 (permalink)  
Old 02-10-05, 04:17 AM
ben.periton ben.periton is offline
Wannabe Coder
 
Join Date: Oct 2004
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
<a href="view2.php?UID=$UID">

Should that not be
<a href="view2.php?UID=<?=$UID?>">

Else it could be trying to lookup where the UID = UID
__________________
Ben Periton
http://ben.periton.co.uk
Reply With Quote
  #5 (permalink)  
Old 02-10-05, 04:44 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
another note:
PHP Code:

$sql2="SELECT title, first_name, last_name FROM users where UID = '$UID' "

or die ("Could not execute select"); 
the or die() part is redundant!
because you are constucting PHP to die if it fails to define the variable, which will never happen!
instead try the or die() on mysql_query()
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #6 (permalink)  
Old 02-10-05, 04:13 PM
tapir tapir is offline
Newbie Coder
 
Join Date: Jan 2005
Location: UK
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Hmm, I've tried the suggestion above,
PHP Code:

<a href="./view2.php?UID=<?=$UID?>">'
and still no joy. I notice that when I put the mouse cursor over the link, the URL is the code above, and not the UID value that I'm trying pass to the next page. Any further suggestions>

And NeverMind - thanks for the tip regarding the 'or die' code - I'll bare that in mind.

:t:
Reply With Quote
  #7 (permalink)  
Old 02-10-05, 05:31 PM
ben.periton ben.periton is offline
Wannabe Coder
 
Join Date: Oct 2004
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
is this a php file? also, is $UID actually being set in this page?
__________________
Ben Periton
http://ben.periton.co.uk
Reply With Quote
  #8 (permalink)  
Old 02-16-05, 04:46 PM
tapir tapir is offline
Newbie Coder
 
Join Date: Jan 2005
Location: UK
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
[solved]

This is the code I used to pass the value to the next page:

PHP Code:

<TD><a href="view2.php?UID=' . $row['UID'] . '">'.$row['UID'].'</a></TD
So I was on the tracks....but not far enough down

thanks for all your input

:t:
Reply With Quote
  #9 (permalink)  
Old 02-16-05, 05:38 PM
Merovingian's Avatar
Merovingian Merovingian is offline
Newbie Coder
 
Join Date: Jan 2004
Location: Los Angeles
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
you can also urlencode() the passing variables so that it's not visible... Just a thought
__________________
"Duo seguere aut de via decede" ...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
$_GET variable from previous page! truesilentassassin PHP 6 07-26-04 09:55 PM
Sending a variable to a page redirected to with header() ? Frank PHP 3 05-19-04 08:02 AM
how to read a web page content to a variable? wings01234 JavaScript 4 01-13-04 08:27 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 05:29 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.