943,700 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 735
  • PHP RSS
Dec 7th, 2008
0

passing vars from DB into iFrame

Expand Post »
Hi to all, php n00b here :-)
I have a simple problem and would like to ask for some help...
What I want to do is this: when our affiliate submits his aff ID into the form, a php script should post that ID from DB, but load it into an iFrame. Here is form an iframe code:

html Syntax (Toggle Plain Text)
  1. <form action="get_Code.php" method="post">
  2. Your affiliate ID: <input type="text" name="affID" />
  3. <input type="submit" />
  4. </form>
  5. <div style="position:absolute;left:0px;top:0px;visibility:hidden;" id="datadiv">
  6. <iframe src="about:blank" height="0" width="0" name="gatewayCode"></iframe>
  7. </div>

And here is messed up php code so far; pls help a little!
Thanks!
Boštjan

php Syntax (Toggle Plain Text)
  1. $conn = mysql_connect("localhost", "mysql_user", "mysql_password");
  2. if (!$conn) {
  3. echo "Unable to connect to DB: " . mysql_error();
  4. exit;
  5. }
  6. if (!mysql_select_db("mydbname")) {
  7. echo "Unable to select mydbname: " . mysql_error();
  8. exit;
  9. }
  10. $id = $_GET['id'];
  11. $sql = "SELECT * FROM users WHERE id = $id";
  12. $result = mysql_query($sql);
  13. if (!$result) {
  14. echo "Could not successfully run query ($sql) from DB: " . mysql_error();
  15. exit;
  16. }
  17. if (mysql_num_rows($result) == 0) {
  18. echo "No rows found, nothing to print so am exiting";
  19. exit;
  20. }
  21. while ($row = mysql_fetch_assoc($result)) {
  22. echo $row["id"];
Last edited by peter_budo; Dec 7th, 2008 at 4:54 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elbuhleini is offline Offline
17 posts
since Apr 2008
Dec 7th, 2008
0

Re: passing vars from DB into iFrame

Click to Expand / Collapse  Quote originally posted by elbuhleini ...
Hi to all, php n00b here :-)
I have a simple problem and would like to ask for some help...
What I want to do is this: when our affiliate submits his aff ID into the form, a php script should post that ID from DB, but load it into an iFrame. Here is form an iframe code:

html Syntax (Toggle Plain Text)
  1. <form action="get_Code.php" method="post">
  2. Your affiliate ID: <input type="text" name="affID" />
  3. <input type="submit" />
  4. </form>
  5. <div style="position:absolute;left:0px;top:0px;visibility:hidden;" id="datadiv">
  6. <iframe src="about:blank" height="0" width="0" name="gatewayCode"></iframe>
  7. </div>

And here is messed up php code so far; pls help a little!
Thanks!
Boštjan

php Syntax (Toggle Plain Text)
  1. $conn = mysql_connect("localhost", "mysql_user", "mysql_password");
  2. if (!$conn) {
  3. echo "Unable to connect to DB: " . mysql_error();
  4. exit;
  5. }
  6. if (!mysql_select_db("mydbname")) {
  7. echo "Unable to select mydbname: " . mysql_error();
  8. exit;
  9. }
  10. $id = $_GET['id'];
  11. $sql = "SELECT * FROM users WHERE id = $id";
  12. $result = mysql_query($sql);
  13. if (!$result) {
  14. echo "Could not successfully run query ($sql) from DB: " . mysql_error();
  15. exit;
  16. }
  17. if (mysql_num_rows($result) == 0) {
  18. echo "No rows found, nothing to print so am exiting";
  19. exit;
  20. }
  21. while ($row = mysql_fetch_assoc($result)) {
  22. echo $row["id"];

You just want to make the IFRAME the target of your FORM.
Give your IFRAME a name, best the same as the ID (as old IE can't distinguish the two).

Then in your FORM:

PHP Syntax (Toggle Plain Text)
  1. <form target="name">

where name is the name of the IFRAME.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Dec 8th, 2008
0

Re: passing vars from DB into iFrame

You just want to make the IFRAME the target of your FORM.
Give your IFRAME a name, best the same as the ID (as old IE can't distinguish the two).

Then in your FORM:

PHP Syntax (Toggle Plain Text)
  1. <form target="name">

where name is the name of the IFRAME.
Hey, thanks a lot! It almost works, but as I am a n00b, this is going wrong:
- I have setup a form, named it "gateway.php", like this
PHP Syntax (Toggle Plain Text)
  1. <form action="get_gateway.php" action="post">
  2. <form target="ifrm">
  3. Your affiliate ID: <input type="text" name="affID" />
  4. <input type="submit" />
  5. </form>

- Then, I setup another page, named "get_gateway.php", which should render an output like this:
PHP Syntax (Toggle Plain Text)
  1. <script language="JavaScript" src="http://mydomain/someJS.js"></script>
  2. <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script>
  3. <link type="text/css" rel="stylesheet" href="http://mydomain/some.css">
  4. <script language="JavaScript">
  5. </script>
  6. <script language="JavaScript" src="http://mydomain/gateway.php?affID={HERE SHOULD BE THE AFFILIATE ID}"></script>
The problem is, that when submitting a form, it renders affID in url bar and redirects to "get_gateway.php" - but the iframe does not show? I used an iframe from previous post, rename its name & id and put the textarea in it, but no luck. This iframe is giving me a headache
Pls, help!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elbuhleini is offline Offline
17 posts
since Apr 2008
Dec 8th, 2008
0

Re: passing vars from DB into iFrame

Click to Expand / Collapse  Quote originally posted by elbuhleini ...
Hey, thanks a lot! It almost works, but as I am a n00b, this is going wrong:
- I have setup a form, named it "gateway.php", like this
PHP Syntax (Toggle Plain Text)
  1. <form action="get_gateway.php" action="post">
  2. <form target="ifrm">
  3. Your affiliate ID: <input type="text" name="affID" />
  4. <input type="submit" />
  5. </form>

- Then, I setup another page, named "get_gateway.php", which should render an output like this:
PHP Syntax (Toggle Plain Text)
  1. <script language="JavaScript" src="http://mydomain/someJS.js"></script>
  2. <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script>
  3. <link type="text/css" rel="stylesheet" href="http://mydomain/some.css">
  4. <script language="JavaScript">
  5. </script>
  6. <script language="JavaScript" src="http://mydomain/gateway.php?affID={HERE SHOULD BE THE AFFILIATE ID}"></script>
The problem is, that when submitting a form, it renders affID in url bar and redirects to "get_gateway.php" - but the iframe does not show? I used an iframe from previous post, rename its name & id and put the textarea in it, but no luck. This iframe is giving me a headache
Pls, help!
You can't have nested forms (a form within a form).

You should just add the "name" attribute to the original form.

eg:

PHP Syntax (Toggle Plain Text)
  1. <form action="get_gateway.php" target="ifrm" method="post">
  2. Your affiliate ID: <input type="text" name="affID" />
  3. <input type="submit" />
  4. </form>

Note that the action="post" should be method="post". The action attribute denotes the url that you want the form to pass its name/value pairs to.

Your IFRAME should be named ifrm.

For your gateway.php file:

PHP Syntax (Toggle Plain Text)
  1. <script language="JavaScript" src="http://mydomain/someJS.js"></script>
  2. <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script>
  3. <link type="text/css" rel="stylesheet" href="http://mydomain/some.css">
  4. <script language="JavaScript">
  5. </script>
  6. <script language="JavaScript" src="http://mydomain/gateway.php?affID=<?php echo urlencode($_POST['affID']); ?>"></script>

The PHP code:

php Syntax (Toggle Plain Text)
  1. <?php echo urlencode($_POST['affID']); ?>

will write the affID value so that the JavaScript file will know what it is.

The urlencode() serves to encode the affID value for URL transmission as well as prevent XSS injection into your page.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Dec 8th, 2008
0

Re: passing vars from DB into iFrame

You can't have nested forms (a form within a form).

You should just add the "name" attribute to the original form.

eg:

PHP Syntax (Toggle Plain Text)
  1. <form action="get_gateway.php" target="ifrm" method="post">
  2. Your affiliate ID: <input type="text" name="affID" />
  3. <input type="submit" />
  4. </form>

Note that the action="post" should be method="post". The action attribute denotes the url that you want the form to pass its name/value pairs to.

Your IFRAME should be named ifrm.

For your gateway.php file:

PHP Syntax (Toggle Plain Text)
  1. <script language="JavaScript" src="http://mydomain/someJS.js"></script>
  2. <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script>
  3. <link type="text/css" rel="stylesheet" href="http://mydomain/some.css">
  4. <script language="JavaScript">
  5. </script>
  6. <script language="JavaScript" src="http://mydomain/gateway.php?affID=<?php echo urlencode($_POST['affID']); ?>"></script>

The PHP code:

php Syntax (Toggle Plain Text)
  1. <?php echo urlencode($_POST['affID']); ?>

will write the affID value so that the JavaScript file will know what it is.

The urlencode() serves to encode the affID value for URL transmission as well as prevent XSS injection into your page.
Thank you for your help, but I still have problems

1. Corrected the form in "gateway.php":
PHP Syntax (Toggle Plain Text)
  1. <form action="get_gateway.php" target="ifrm" method="post">
  2. Your affiliate ID: <input type="text" name="affID" />
  3. <input type="submit" />
  4. </form>
2. Corrected the iframe in "get_gateway.php":
PHP Syntax (Toggle Plain Text)
  1. <iframe name="ifrm" id="ifrm" width="400" height="200"><script language="JavaScript" src="http://mydomain/someJS.js"></script>
  2. <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script>
  3. <link type="text/css" rel="stylesheet" href="http://mydomain/some.css">
  4. <script language="JavaScript">
  5. </script>
  6. <script language="JavaScript" src="http://mydomain.com/gateway.php?affID=<?php echo urlencode($_POST['affID']); ?>"></script></iframe>
The problem is that iframe does not show up?
What am I doing wrong?
Thx,
Boštjan
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elbuhleini is offline Offline
17 posts
since Apr 2008
Dec 8th, 2008
0

Re: passing vars from DB into iFrame

Click to Expand / Collapse  Quote originally posted by elbuhleini ...
Thank you for your help, but I still have problems

1. Corrected the form in "gateway.php":
PHP Syntax (Toggle Plain Text)
  1. <form action="get_gateway.php" target="ifrm" method="post">
  2. Your affiliate ID: <input type="text" name="affID" />
  3. <input type="submit" />
  4. </form>
2. Corrected the iframe in "get_gateway.php":
PHP Syntax (Toggle Plain Text)
  1. <iframe name="ifrm" id="ifrm" width="400" height="200"><script language="JavaScript" src="http://mydomain/someJS.js"></script>
  2. <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script>
  3. <link type="text/css" rel="stylesheet" href="http://mydomain/some.css">
  4. <script language="JavaScript">
  5. </script>
  6. <script language="JavaScript" src="http://mydomain.com/gateway.php?affID=<?php echo urlencode($_POST['affID']); ?>"></script></iframe>
The problem is that iframe does not show up?
What am I doing wrong?
Thx,
Boštjan
Place what you want to go in the IFRAME into the file gateway.php

An IFRAME only takes a src attribute. It does not take any content as you have done. The content is only alternative content if the browser does not support IFRAMES.
http://www.w3.org/TR/REC-html40/pres...es.html#h-16.5

So for the IFRAME:

PHP Syntax (Toggle Plain Text)
  1. <iframe name="ifrm" id="ifrm" width="400" height="200" ></iframe>

Then in gateway.php

PHP Syntax (Toggle Plain Text)
  1. <script language="JavaScript" src="http://mydomain/someJS.js"></script>
  2. <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script>
  3. <link type="text/css" rel="stylesheet" href="http://mydomain/some.css">
  4. <script language="JavaScript">
  5. </script>
  6. <script language="JavaScript" src="http://mydomain.com/gateway.php?affID=<?php echo urlencode($_POST['affID']); ?>"></script>
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: code for downloading as doc file
Next Thread in PHP Forum Timeline: Telugu Version





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC