passing vars from DB into iFrame

Reply

Join Date: Apr 2008
Posts: 17
Reputation: elbuhleini is an unknown quantity at this point 
Solved Threads: 0
elbuhleini's Avatar
elbuhleini elbuhleini is offline Offline
Newbie Poster

passing vars from DB into iFrame

 
0
  #1
Dec 7th, 2008
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:

  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

  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.
If you think you are the smartest, you definetly are not. But you can strive to be one. Cashwizz Affiliate network
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: passing vars from DB into iFrame

 
0
  #2
Dec 7th, 2008
Originally Posted by elbuhleini View 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:

  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

  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:

  1. <form target="name">

where name is the name of the IFRAME.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 17
Reputation: elbuhleini is an unknown quantity at this point 
Solved Threads: 0
elbuhleini's Avatar
elbuhleini elbuhleini is offline Offline
Newbie Poster

Re: passing vars from DB into iFrame

 
0
  #3
Dec 8th, 2008
Originally Posted by digital-ether View Post
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:

  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
  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:
  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!
If you think you are the smartest, you definetly are not. But you can strive to be one. Cashwizz Affiliate network
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: passing vars from DB into iFrame

 
0
  #4
Dec 8th, 2008
Originally Posted by elbuhleini View Post
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
  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:
  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:

  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:

  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:

  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.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 17
Reputation: elbuhleini is an unknown quantity at this point 
Solved Threads: 0
elbuhleini's Avatar
elbuhleini elbuhleini is offline Offline
Newbie Poster

Re: passing vars from DB into iFrame

 
0
  #5
Dec 8th, 2008
Originally Posted by digital-ether View Post
You can't have nested forms (a form within a form).

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

eg:

  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:

  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:

  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":
  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":
  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
If you think you are the smartest, you definetly are not. But you can strive to be one. Cashwizz Affiliate network
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: passing vars from DB into iFrame

 
0
  #6
Dec 8th, 2008
Originally Posted by elbuhleini View Post
Thank you for your help, but I still have problems

1. Corrected the form in "gateway.php":
  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":
  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:

  1. <iframe name="ifrm" id="ifrm" width="400" height="200" ></iframe>

Then in gateway.php

  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>
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC