<form action="get_Code.php" method="post"> Your affiliate ID: <input type="text" name="affID" /> <input type="submit" /> </form> <div style="position:absolute;left:0px;top:0px;visibility:hidden;" id="datadiv"> <iframe src="about:blank" height="0" width="0" name="gatewayCode"></iframe> </div>
$conn = mysql_connect("localhost", "mysql_user", "mysql_password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("mydbname")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $id = $_GET['id']; $sql = "SELECT * FROM users WHERE id = $id"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo $row["id"];
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)
<form action="get_Code.php" method="post"> Your affiliate ID: <input type="text" name="affID" /> <input type="submit" /> </form> <div style="position:absolute;left:0px;top:0px;visibility:hidden;" id="datadiv"> <iframe src="about:blank" height="0" width="0" name="gatewayCode"></iframe> </div>
And here is messed up php code so far; pls help a little!
Thanks!
Boštjan
php Syntax (Toggle Plain Text)
$conn = mysql_connect("localhost", "mysql_user", "mysql_password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("mydbname")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $id = $_GET['id']; $sql = "SELECT * FROM users WHERE id = $id"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo $row["id"];
<form target="name">
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)
<form target="name">
where name is the name of the IFRAME.
<form action="get_gateway.php" action="post"> <form target="ifrm"> Your affiliate ID: <input type="text" name="affID" /> <input type="submit" /> </form>
<script language="JavaScript" src="http://mydomain/someJS.js"></script> <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script> <link type="text/css" rel="stylesheet" href="http://mydomain/some.css"> <script language="JavaScript"> </script> <script language="JavaScript" src="http://mydomain/gateway.php?affID={HERE SHOULD BE THE AFFILIATE ID}"></script>
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)
<form action="get_gateway.php" action="post"> <form target="ifrm"> Your affiliate ID: <input type="text" name="affID" /> <input type="submit" /> </form>
- Then, I setup another page, named "get_gateway.php", which should render an output like this:
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 headachePHP Syntax (Toggle Plain Text)
<script language="JavaScript" src="http://mydomain/someJS.js"></script> <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script> <link type="text/css" rel="stylesheet" href="http://mydomain/some.css"> <script language="JavaScript"> </script> <script language="JavaScript" src="http://mydomain/gateway.php?affID={HERE SHOULD BE THE AFFILIATE ID}"></script>![]()
Pls, help!
<form action="get_gateway.php" target="ifrm" method="post"> Your affiliate ID: <input type="text" name="affID" /> <input type="submit" /> </form>
<script language="JavaScript" src="http://mydomain/someJS.js"></script> <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script> <link type="text/css" rel="stylesheet" href="http://mydomain/some.css"> <script language="JavaScript"> </script> <script language="JavaScript" src="http://mydomain/gateway.php?affID=<?php echo urlencode($_POST['affID']); ?>"></script>
<?php echo urlencode($_POST['affID']); ?>
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)
<form action="get_gateway.php" target="ifrm" method="post"> Your affiliate ID: <input type="text" name="affID" /> <input type="submit" /> </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)
<script language="JavaScript" src="http://mydomain/someJS.js"></script> <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script> <link type="text/css" rel="stylesheet" href="http://mydomain/some.css"> <script language="JavaScript"> </script> <script language="JavaScript" src="http://mydomain/gateway.php?affID=<?php echo urlencode($_POST['affID']); ?>"></script>
The PHP code:
php Syntax (Toggle Plain Text)
<?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.
<form action="get_gateway.php" target="ifrm" method="post"> Your affiliate ID: <input type="text" name="affID" /> <input type="submit" /> </form>
<iframe name="ifrm" id="ifrm" width="400" height="200"><script language="JavaScript" src="http://mydomain/someJS.js"></script> <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script> <link type="text/css" rel="stylesheet" href="http://mydomain/some.css"> <script language="JavaScript"> </script> <script language="JavaScript" src="http://mydomain.com/gateway.php?affID=<?php echo urlencode($_POST['affID']); ?>"></script></iframe>
Thank you for your help, but I still have problems![]()
1. Corrected the form in "gateway.php":
2. Corrected the iframe in "get_gateway.php":PHP Syntax (Toggle Plain Text)
<form action="get_gateway.php" target="ifrm" method="post"> Your affiliate ID: <input type="text" name="affID" /> <input type="submit" /> </form>
The problem is that iframe does not show up?PHP Syntax (Toggle Plain Text)
<iframe name="ifrm" id="ifrm" width="400" height="200"><script language="JavaScript" src="http://mydomain/someJS.js"></script> <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script> <link type="text/css" rel="stylesheet" href="http://mydomain/some.css"> <script language="JavaScript"> </script> <script language="JavaScript" src="http://mydomain.com/gateway.php?affID=<?php echo urlencode($_POST['affID']); ?>"></script></iframe>
What am I doing wrong?
Thx,
Boštjan
<iframe name="ifrm" id="ifrm" width="400" height="200" ></iframe>
<script language="JavaScript" src="http://mydomain/someJS.js"></script> <script language="JavaScript" src="http://mydomain/some_moreJS.js"></script> <link type="text/css" rel="stylesheet" href="http://mydomain/some.css"> <script language="JavaScript"> </script> <script language="JavaScript" src="http://mydomain.com/gateway.php?affID=<?php echo urlencode($_POST['affID']); ?>"></script>
| DaniWeb Message | |
| Cancel Changes | |