passed variable not displaying

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pugs
Forum Newbie
Posts: 5
Joined: Tue Jun 24, 2008 5:28 pm

passed variable not displaying

Post by pugs »

Hi,

Hope someone can help, I've been trying this for ages :(

I am passing a training course id variable within a URL so the link from the list of training courses is:

Code: Select all

<a href=\"course_material.php?$row[course_id]\">
That bit seems to work ok as I can see the correct url in the browser with correct variable. However the problem occurs when trying to display the passed variable. this is the code I have on the page I want it to display

Code: Select all

 
$course_id=$_GET['course_id'];{
echo "this is the course ID $course_id";}
I don't get any errors just a blank space where the course ID number should be.

Any help appreciated.

Thanks

Lisa
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: passed variable not displaying

Post by The_Anomaly »

Try removing the { and } you have in there for some reason. Not sure if this would cause that kind of problem--but they certainly are not necessary. Aside from that, I can't see any other reason why this would not work:

Code: Select all

 
 $course_id=$_GET['course_id'];
 
 echo "this is the course ID $course_id";
 
EDIT:
Ah, and you also made a mistake when creating your querystring. You want this:

Code: Select all

 
<a href="course_material.php?course_id=<?php echo $row[course_id] ?>"
 
You have define the name of the URL variable to be able to use it later on.
Last edited by The_Anomaly on Mon Sep 29, 2008 4:01 pm, edited 1 time in total.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: passed variable not displaying

Post by markusn00b »

The_Anomaly wrote:Try removing the { and } you have in there for some reason. Not sure if this would cause that kind of problem--but they certainly are not necessary. Aside from that, I can't see any other reason why this would not work:

Code: Select all

 
 $course_id=$_GET['course_id'];
 
 echo "this is the course ID $course_id";
 
That won't work because there is no 'course_id' parameter.

Try

Code: Select all

 
<a href=\"course_material.php?course_id=$row[course_id]\">
 
 
and then

Code: Select all

 
 $course_id=$_GET['course_id'];
 
 echo "this is the course ID $course_id";
 
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: passed variable not displaying

Post by The_Anomaly »

Ah, I edited before I saw your post, Marcus. But yeah, I didn't see that when I first posted.
pugs
Forum Newbie
Posts: 5
Joined: Tue Jun 24, 2008 5:28 pm

Re: passed variable not displaying

Post by pugs »

thank you - works perfectly!
Post Reply