jt327 Posted November 20, 2006 Share Posted November 20, 2006 Hey Guys,I know this is a common problem for people new to php, and ive done a lot of research before posting but so far cannot get it working. My problem is:i am trying to pass variables to a html page through the url : http://url.com/index.php?id=123&var=0 but am having trouble getting the variable from the other page. should i be doing something like..<?php$var= $_GET['var'];echo "the variable is: $var";?> If so is there a problem with this code? Will that php code work fine imbedded in a plain html file? or will i have to add somethin else? any help would be massively appreciatedThanks in advance,Jared Link to comment https://forums.phpfreaks.com/topic/27911-php-variable-passing-through-url-not-working/ Share on other sites More sharing options...
Destramic Posted November 20, 2006 Share Posted November 20, 2006 index.php?id=0001&var=22[code]<?php$id = $_GET['id'];$var = $_GET['var'];echo "id:" . $id;echo "var:" . $var;?>[/code] Link to comment https://forums.phpfreaks.com/topic/27911-php-variable-passing-through-url-not-working/#findComment-127644 Share on other sites More sharing options...
jt327 Posted November 20, 2006 Author Share Posted November 20, 2006 Hi Destramic,Thanks for your quick reply. If i then wanted to reference the variables inside the html file, but outsite of the php code block, how would i go about doing this?Jared. Link to comment https://forums.phpfreaks.com/topic/27911-php-variable-passing-through-url-not-working/#findComment-127650 Share on other sites More sharing options...
roopurt18 Posted November 20, 2006 Share Posted November 20, 2006 You can jump in and out of HTML with <? and ?>[code]<html> <head> </head> <body> <? echo $_GET['id']; ?> </body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/27911-php-variable-passing-through-url-not-working/#findComment-127651 Share on other sites More sharing options...
Destramic Posted November 20, 2006 Share Posted November 20, 2006 <?php echo $id; ?>using php at the opening tag is good practice...sorry Link to comment https://forums.phpfreaks.com/topic/27911-php-variable-passing-through-url-not-working/#findComment-127656 Share on other sites More sharing options...
jt327 Posted November 20, 2006 Author Share Posted November 20, 2006 hey guys sorry im really new to this, so a bit slow..would there be any way for me to access the variable through html without jumping into php with the <?php ?> tags? Link to comment https://forums.phpfreaks.com/topic/27911-php-variable-passing-through-url-not-working/#findComment-127660 Share on other sites More sharing options...
Philip Posted November 20, 2006 Share Posted November 20, 2006 Javascript... not using any script - I can't think of anything off the top of my head. Why do you need it to where you can't run the PHP script? Link to comment https://forums.phpfreaks.com/topic/27911-php-variable-passing-through-url-not-working/#findComment-127662 Share on other sites More sharing options...
jt327 Posted November 20, 2006 Author Share Posted November 20, 2006 well basically ive got a html page which im trying to adapt to php to work with my content management system. in the html file ive got a javascript function call which passes one of the variables passed to the page. somehting like..myFunction(var);what im trying to do is read in the var from the <?php $var= $_GET['var'];?>and then pass it to myFunction(). Im not the best coder so im not sure about the best way to go about this.Jared. Link to comment https://forums.phpfreaks.com/topic/27911-php-variable-passing-through-url-not-working/#findComment-127664 Share on other sites More sharing options...
Destramic Posted November 20, 2006 Share Posted November 20, 2006 im not sure on what you want to do but to use inside a function do something like this[code]<?phpfunction vars();{ echo $_GET['var']; echo $_GET['id'];}// display functionecho vars();?>[/code] Link to comment https://forums.phpfreaks.com/topic/27911-php-variable-passing-through-url-not-working/#findComment-127666 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.