5

I've not used PHP much (or at all) before, and I have the following code:

<?php
$val = $_GET['ID'];
echo "<iframe src='sitename.com.au/directory/app/pagename.cfm?memberid='$val'    width='100%' scrolling='vertical'></iframe>";
?>

I think that should be ok to take a URL variable and pass it to an Iframe url...my issue is that when I hit the page this is on instead of it being:

http://sitename.com/whats-on?ID=2

its

http://sitename.com/whats-on/?ID=2

I don't know where that slash before /?ID is coming from - but I believe it is causing my problem - the iframe displaying a page not found message.

Any advice appreciated.

Thanks

Simon

3 Answers 3

7

iFrames just take a url - and parameters can be embedded in urls just fine.

The problem, if I understand the question clearly, is that you're mixing up your quotes:

 echo "<iframe src='sitename.com.au/directory/app/pagename.cfm?memberid='$val'
        width='100%' scrolling='vertical'></iframe>";

will be outputted as

 <iframe src='sitename.com.au/directory/app/pagename.cfm?memberid=' 21254545' 
  width='100%' scrolling='vertical'></iframe>

where 21254545 is an attribute of the iframe instead of part of the url.

Assuming that you don't actually need the quotes in the url, change the echo line to:

echo "<iframe src='sitename.com.au/directory/app/pagename.cfm?memberid=$val' width='100%' scrolling='vertical'></iframe>";

And it should work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks MackieChan! - appreciate the help!
1
  • Add http:// before sitename.com.au/
  • Change memberid='$val' to memberid=$val' [remove that single quote on left of $val]
<?php
   $val = $_GET['ID'];
   echo "<iframe src='sitename.com.au/directory/app/pagename.cfm?memberid=$val' width='100%' scrolling='vertical'></iframe>";
?>

Comments

0

Seems that the

echo "<iframe src='sitename.com.au/directory/app/pagename.cfm?memberid=$val' width='100%' scrolling='vertical'></iframe>";

doesn't work anymore. You have to add the variable like this

 echo "<iframe src='sitename.com.au/directory/app/pagename.cfm?memberid=".$val."' width='100%' scrolling='vertical'></iframe>";

Since the anwser was from 2012... maybe PHP patched it to be used like that now.

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.