ridiculous Posted November 28, 2006 Share Posted November 28, 2006 Hi. I'm trying to pass variables through an image link like so:===================================================================echo '<div> <a href="course_details_index.php? '.$Course_Id.' &'.$Course_Begin_Time.' &'.$Instructor_1.'"> <img src="media/course_pics/'.$Course_Pic .'" alt="Featured Course Image" border="none" img style="position:absolute; height:300px; width:300px; TOP:0px; LEFT:0px;"></a> </div>';=====================================================================When I pass the variables through the link, they come out as raw data on the address bar of the target page, and I get nothing when I try to print or echo them. print $Course_Id; = Blank Spaceecho $Course_Id; = Blank Space How do I fix this so that I can print the variables out as needed or have them available to run a mysql query? Quote Link to comment https://forums.phpfreaks.com/topic/28681-how-do-i-retrieve-variables-passed-thru-the-url/ Share on other sites More sharing options...
The Little Guy Posted November 28, 2006 Share Posted November 28, 2006 echo '<div> <a href="course_details_index.php? '.$Course_Id.' &'.$Course_Begin_Time.' &'.$Instructor_1.'"> <img src="media/course_pics/index.php?pic='.$Course_Pic .'" alt="Featured Course Image" border="none" img style="position:absolute; height:300px; width:300px; TOP:0px; LEFT:0px;">[/url] </div>';=====================================================================echo $_GET['pic']; Quote Link to comment https://forums.phpfreaks.com/topic/28681-how-do-i-retrieve-variables-passed-thru-the-url/#findComment-131268 Share on other sites More sharing options...
Caesar Posted November 28, 2006 Share Posted November 28, 2006 That all looked kinda messy to me so I'll just repost :) :If your requesting url looks like:[color=blue]http://mydomain.com/index.php?name=bob&id=123[/color]Then, you'd retrieve the value of that variable like so:[code]<?php$myname = $_GET['name'];$myid = $_GET['id'];echo"My name is $myname and my id number is $myid, sucka!!";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28681-how-do-i-retrieve-variables-passed-thru-the-url/#findComment-131274 Share on other sites More sharing options...
doni49 Posted November 28, 2006 Share Posted November 28, 2006 1) You haven't set the variable in the URL.2) You haven't told it to get the variable from the URL.Create the URL:[code]<?phpecho '<div> <a href="course_details_index.php? Course_Id='.$Course_Id.' &Course_Begin_Time='.$Course_Begin_Time.' &Instructor_1='.$Instructor_1.'"> <img src="media/course_pics/'.$Course_Pic .'" alt="Featured Course Image" border="none" img style="position:absolute; height:300px; width:300px; TOP:0px; LEFT:0px;">[/url] </div>';?>[/code]Then in the page that is called from that link:[code]<?php echo '<br />" . $_GET['Course_Id']; echo '<br />" . $_GET['Course_Begin_Time']; echo '<br />" . $_GET['Instructor_1'];?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28681-how-do-i-retrieve-variables-passed-thru-the-url/#findComment-131275 Share on other sites More sharing options...
ridiculous Posted November 28, 2006 Author Share Posted November 28, 2006 Wow. None of these things are working. Quote Link to comment https://forums.phpfreaks.com/topic/28681-how-do-i-retrieve-variables-passed-thru-the-url/#findComment-131283 Share on other sites More sharing options...
doni49 Posted November 28, 2006 Share Posted November 28, 2006 Well I see an error in my code. I mixed quote types.In the second bit of code:[code]<?php echo '<br />' . $_GET['Course_Id']; echo '<br />' . $_GET['Course_Begin_Time']; echo '<br />' . $_GET['Instructor_1'];?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28681-how-do-i-retrieve-variables-passed-thru-the-url/#findComment-131327 Share on other sites More sharing options...
ridiculous Posted November 28, 2006 Author Share Posted November 28, 2006 My the url in my address bar looks like this after I hit the link:http://localhost/SS/course_details_index.php?name=PHP100MSULab48823Does anyone know how to print the variable given in the url above? Quote Link to comment https://forums.phpfreaks.com/topic/28681-how-do-i-retrieve-variables-passed-thru-the-url/#findComment-131443 Share on other sites More sharing options...
fiddy Posted November 28, 2006 Share Posted November 28, 2006 Can you try this...echo '<div> <a href="course_details_index.php?Course_Id= '.$Course_Id.' &Course_Begin_Time='.$Course_Begin_Time.' &Instructor_1='.$Instructor_1.'"> <img src="media/course_pics/'.$Course_Pic .'" alt="Featured Course Image" border="none" img style="position:absolute; height:300px; width:300px; TOP:0px; LEFT:0px;">[/url] </div>'; Quote Link to comment https://forums.phpfreaks.com/topic/28681-how-do-i-retrieve-variables-passed-thru-the-url/#findComment-131448 Share on other sites More sharing options...
fiddy Posted November 28, 2006 Share Posted November 28, 2006 Hope you are getting those values like this $Course_Id=$_GET['Course_Id'];$Course_Begin_Time = $_GET['Course_Begin_Time'];$Instructor_1 = $_GET['Instructor_1']; Quote Link to comment https://forums.phpfreaks.com/topic/28681-how-do-i-retrieve-variables-passed-thru-the-url/#findComment-131450 Share on other sites More sharing options...
trq Posted November 28, 2006 Share Posted November 28, 2006 [quote]Does anyone know how to print the variable given in the url above?[/quote][code=php:0]echo $_GET['name'];[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28681-how-do-i-retrieve-variables-passed-thru-the-url/#findComment-131465 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.