0

I'm trying to pass the return value of a php function through query string but its not working. Please look into the code below:

Here I'm trying to replace $myvar in the query string.

<button onClick="parent.location='http://www.example.com&id=$myvar'">Design Your product</button> 

The php function to retrieve $myvar is given below:

<?php
$myvar=Design();
function Design() 
 {
// my function code

return $result;
}

2 Answers 2

4
<button onClick="parent.location='http://www.example.com&id=<?php echo $myvar; ?>'">Design Your product</button> 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanx 4 ur immediate help but i'm still getting error. It says "Call to undefined funtion Design()" Have i made mistake in the function call ?? <?php $myvar=Design(); function Design() { // my function code return $result; }
See Trogvar's answer - You must tell the preprocessor what the definition of the function is before you call it. Setting $myvar to Design() before the actual function is defined results, predictably, in a Call to undefined function Design().
0

You try to call the function before it has been defined. This should work

<?php
    function Design()
    {
         return "something";
    }
    $myvar = Design();
?>
<button onClick="parent.location='http://www.example.com?id=<?php echo $myvar; ?>'">Design Your product</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.