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:

<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

$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:

<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

$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"];

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:

<form target="name">

where name is the name of the 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:

<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

<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:

<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>

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!

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

<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:

<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>

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:

<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:

<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 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.

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

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

eg:

<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:

<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 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":

<form action="get_gateway.php" target="ifrm" method="post"> 
Your affiliate ID: <input type="text" name="affID" />
<input type="submit" />
</form>

2. Corrected the iframe in "get_gateway.php":

<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>

The problem is that iframe does not show up?
What am I doing wrong?
Thx,
Boštjan

Thank you for your help, but I still have problems :(

1. Corrected the form in "gateway.php":

<form action="get_gateway.php" target="ifrm" method="post"> 
Your affiliate ID: <input type="text" name="affID" />
<input type="submit" />
</form>

2. Corrected the iframe in "get_gateway.php":

<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>

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/present/frames.html#h-16.5

So for the IFRAME:

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

Then in gateway.php

<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>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.