Jump to content
mickeymouse

Passing Paramater via PHP call

Recommended Posts

How do I pass a parameter (myparam) to the page I'm calling via a function.

function ancesterF(myparam)
{location.href=\"FT_Search2.php\";return false;
window.open(location.href); return false;}

Tks
 

Share this post


Link to post
Share on other sites

Thank you dsonesuk.

I should also have asked you how do I capture the param in my called page.

 

Edited by mickeymouse

Share this post


Link to post
Share on other sites

I tried that but I end up with the value of my $getmyparam being equal to "myparam" instead of the value passed which in my  test case is "10006"

In my calling function, I confirm the value of "myparam" and it is "10006".

CALLING CODE:

function ancesterF(myparam)
{alert(myparam);  <----------------------------------------------------------------------------------This confirms the value "10006"
location.href='FT_Search2.php?param=myparam';return false;
window.open(location.href); return false;}

 

RECIEVING CODE:

$getmyparam =$_GET['param'];

print("getmyparam");  <------------------------------- Result = "myparam"  not "10006"

 

Share this post


Link to post
Share on other sites

Hello, @mickeymouse

Please try this code for passing parameter into URL and to get parameter in current page and also for redirected page.

To get parameter value in current page use this code :

<?php  
$url = 'http://www.geeksforgeeks.org/register?name=Demo&email=demo@gmail.com'; 
     
$url_components = parse_url($url); 
  
parse_str($url_components['query'], $params); 
      
echo ' Hi '.$params['name'].' your emailID is '.$params['email']; 
  
?> 

To get parameter value for redirected page use this code :

<?php

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];

echo " Hi ".$name." your emailId is ".$email;

?>

For both code output will be :

Hi Demo your emailId is demo@gmail.com

I hope above information will be useful for you.
Thank you.

Share this post


Link to post
Share on other sites

He is passing the varible as a string, when he should concatenate the variable after the string up to equals sign.

	location.href='FT_Search2.php?param='+myparam;
	

Share this post


Link to post
Share on other sites

I'm using the following according to dsonesuk advice and it works fine..

To pass the parameter:

function ancester(myparam)
{if(myparam==''){return false;}
location.href='FT_Search2.php?param='+myparam;return false;
window.open(location.href); return false;}

To get the parameter:

{$reqref=$_GET['param'];}

Thanks for the help!

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...