Page 1 of 1

passed variable not displaying

Posted: Mon Sep 29, 2008 3:50 pm
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

Re: passed variable not displaying

Posted: Mon Sep 29, 2008 3:58 pm
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.

Re: passed variable not displaying

Posted: Mon Sep 29, 2008 4:00 pm
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";
 

Re: passed variable not displaying

Posted: Mon Sep 29, 2008 4:03 pm
by The_Anomaly
Ah, I edited before I saw your post, Marcus. But yeah, I didn't see that when I first posted.

Re: passed variable not displaying

Posted: Mon Sep 29, 2008 4:30 pm
by pugs
thank you - works perfectly!