Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variables to iframe using PHP

Status
Not open for further replies.

kitfox69

Technical User
Aug 6, 2008
36
0
0
US
I want to be able to pass these two variables to the iframe so that they can be used in the Insert statement of the iframe source page and be written to the database tables.

Here are the codes:

getcustid5:
Code:
<?php
print('<iframe align="right"
src ="updnps1.php?billdate=' . $billdate . '&amp;custid=' . $sls_his_cust_id . '"
height="550"
width="36%">
</iframe>');
$conn = odbc_connect("HOMES", "", "");
if (!empty($_POST['billdate'])){
    $billdate = $_POST[ 'billdate' ];
    $query = "SELECT DISTINCT sls_his_cust_id FROM sls_his where sls_his_prchdat_alt = $billdate";
    $result = odbc_exec($conn, $query);
    $options = '';
    while($row = odbc_fetch_array($result)){
        $options .= "\t\t<option value=\"{$row[sls_his_cust_id]}\">{$row[sls_his_cust_id]}</OPTION>\r\n";
    }
    echo  <<<HTML
<form method="post" action="getcustid5.php">
    <div>
        <select name="sls_his_cust_id">
        {$options}
        </select>
        <input type="submit" name="custid" value="Get Data">
        <input type="hidden" name="billdate"value="$billdate" />
    </div>
</FORM>
HTML;
}
if (isset($_POST['custid'])) {
    $sls_his_cust_id = $_POST['sls_his_cust_id'];
}
$query1 = ("SELECT DISTINCT sls_his_cust_id as 'Customer ID',
sls_his_d2_nam as 'Customer Name',
cust_phone_no as 'Phone Number 1',
cust_phone_no_2 as 'Phone Number 2',
cust_phone_no_3 as 'Phone Number 3'
FROM sls_his , cust
where CUST_ID = SLS_HIS_CUST_ID
and sls_his_cust_id = '$sls_his_cust_id'");
$query2 = ("SELECT DISTINCT sls_his_pft_ctr as 'Profit Center',
UPPER(slm_nam) as 'Sales Person'
FROM sls_his, slm
where sls_his_slm_1 = slm
and sls_his_cust_id = '$sls_his_cust_id'");
$query3 = ("SELECT sls_his_item_id as 'Item ID',
sum(sls_his_qty_sld) as 'Quantity Sold',
sls_his_prchdat_alt as 'Billed Date',
sls_his_del_via as 'Ship Via'
FROM sls_his
where sls_his_cust_id = '$sls_his_cust_id'
Group by sls_his_item_id, sls_his_prchdat_alt, sls_his_del_via
Order by sls_his_prchdat_alt DESC");
$result1 = odbc_exec($conn, $query1);
$result2 = odbc_exec($conn, $query2);
$result3 = odbc_exec($conn, $query3);
?>
</BR>
<?php
odbc_result_all($result1)

?>
</BR>
<?php
odbc_result_all($result2)

?>
</BR>
<?php
odbc_result_all($result3)

?>

updnps1.php:
Code:
<?php echo $_GET[ 'billdate' ];
echo $_GET[ 'custid' ];
?>
<form action="updnps.php" method="post"
<p> First Attempt</p>
<input type="radio" name="ans1" value="1"> Answer
</BR>
<input type="radio" name="ans1" value="0"> NoAnswer
</BR>
<p> NPS SCORE</p>
<select name="nps">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</BR>
<p> CUSTOMER COMMENTS</p>
<textarea rows="4" cols="40" name="comments1"></textarea>
</BR>
<p> USER COMMENTS</p>
<textarea rows="4" cols="40" name="comments2"></textarea>
</BR>
<p> EMAIL</p>
<input type="text" name="email" /></label>
</BR>
<input type="submit" value="GO" />
</form>
</body>
</html>

I view the pagesource when getcustid5 is loaded in forefox and can see that the variables are not being shown in the url for the iframe src. All I need it to do is show what the selected billdate and custid are for getcustid5 the last time it is called to display the data.

I am pretty sure the updnps.php is fine as it parses and returns the thanks print but it does not run the query as billdate is not set from not getting the variable.
 
well. you only declare $billdate in the code block BELOW the print() statement. perhaps if you swapped these around you might have more success. As is, you are, essentially, requiring php to read your mind as to what you might want $billdate to be.
 
I got it... I hope... it seems to write the data to the database correctly.

getcustid5.php
Code:
<?php
print('<iframe align="right"
src ="updnps1.php?npsbilldate=' . $_POST[ 'billdate' ] . '&npscustid=' . $_POST[ 'sls_his_cust_id' ] . '"
height="550"
width="36%">
</iframe>');
$conn = odbc_connect("HOMES", "", "");
if (!empty($_POST['billdate'])){
    $billdate = $_POST[ 'billdate' ];
    $query = "SELECT DISTINCT sls_his_cust_id FROM sls_his where sls_his_prchdat_alt = $billdate";
    $result = odbc_exec($conn, $query);
    $options = '';
    while($row = odbc_fetch_array($result)){
        $options .= "\t\t<option value=\"{$row[sls_his_cust_id]}\">{$row[sls_his_cust_id]}</OPTION>\r\n";
    }
    echo  <<<HTML
<form method="post" action="getcustid5.php">
    <div>
        <select name="sls_his_cust_id">
        {$options}
        </select>
        <input type="submit" name="custid" value="Get Data">
        <input type="hidden" name="billdate"value="$billdate" />
    </div>
</FORM>
HTML;
}
if (isset($_POST['custid'])) {
    $sls_his_cust_id = $_POST['sls_his_cust_id'];
}
$query1 = ("SELECT DISTINCT sls_his_cust_id as 'Customer ID',
sls_his_d2_nam as 'Customer Name',
cust_phone_no as 'Phone Number 1',
cust_phone_no_2 as 'Phone Number 2',
cust_phone_no_3 as 'Phone Number 3'
FROM sls_his , cust
where CUST_ID = SLS_HIS_CUST_ID
and sls_his_cust_id = '$sls_his_cust_id'");
$query2 = ("SELECT DISTINCT sls_his_pft_ctr as 'Profit Center',
UPPER(slm_nam) as 'Sales Person'
FROM sls_his, slm
where sls_his_slm_1 = slm
and sls_his_cust_id = '$sls_his_cust_id'");
$query3 = ("SELECT sls_his_item_id as 'Item ID',
sum(sls_his_qty_sld) as 'Quantity Sold',
sls_his_prchdat_alt as 'Billed Date',
sls_his_del_via as 'Ship Via'
FROM sls_his
where sls_his_cust_id = '$sls_his_cust_id'
Group by sls_his_item_id, sls_his_prchdat_alt, sls_his_del_via
Order by sls_his_prchdat_alt DESC");
$result1 = odbc_exec($conn, $query1);
$result2 = odbc_exec($conn, $query2);
$result3 = odbc_exec($conn, $query3);
?>
</BR>
<?php
odbc_result_all($result1)

?>
</BR>
<?php
odbc_result_all($result2)

?>
</BR>
<?php
odbc_result_all($result3)

?>

updnps1.php
Code:
<?php
$npsbilldate=$_GET[ 'npsbilldate' ];
$npscustid=$_GET[ 'npscustid' ];
echo $npsbilldate;
?>
</BR>
<?php echo $npscustid;
echo <<<HTML
<form action="updnps.php"
<p> First Attempt</p>
<input type="radio" name="ans1" value="1"> Answer
</BR>
<input type="radio" name="ans1" value="0"> No Answer
</BR>
<p> NPS SCORE</p>
<select name="nps">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</BR>
<p> CUSTOMER COMMENTS</p>
<textarea rows="4" cols="40" name="comments1"></textarea>
</BR>
<p> USER COMMENTS</p>
<textarea rows="4" cols="40" name="comments2"></textarea>
</BR>
<p> EMAIL</p>
<input type="text" name="email"/>
</BR>
<input type="submit" value="GO"
<input type="hidden" name="npsbilldate"value="$npsbilldate"
<input type="hidden" name="npscustid"value="$npscustid"/>
</form>
HTML;
?>

updnps.php
Code:
<?php
$conn = odbc_connect("NETPROSCORE", "", "");
    $npsbilldate = $_GET[ 'npsbilldate' ];
   	$npscustid = $_GET[ 'npscustid' ];
    $ans1 = $_GET[ 'ans1' ];
    $nps = $_GET[ 'nps' ];
    $comments1 = $_GET[ 'comments1' ];
    $comments2 = $_GET[ 'comments2' ];
    $email = $_GET[ 'email' ];
$query = "INSERT INTO nps (nps_call1_date, nps_cust_id, nps_bill_date, nps_ans1, nps, nps_comments1, nps_comments2, nps_email) VALUES (CURDATE(), '$npscustid', '$npsbilldate', '$ans1', '$nps', '$comments1', '$comments2', '$email')";
$result1 = odbc_exec($conn, $query);
print($result1);
?>

One last thing though... the final output is not good as it says Resource id#3. This is the result of the Print($result1) call... how can I call this query without outputting this message?
 
$result1 is a resource handle. it's the output from an odbc_exec call.

once you have a resource then you need to iterate or otherwise use the recordset.

odbc_result_all() should print the recordset if that's what you're interested in.
 
As it is calling an INSERT statement as the result print or odbc_result_all are not the best... do I need to use one of those to still execute the result?
 
If you don't need it printed, then just don't use the print statement on it. The command is executed the line before, when it is assigned to the variable.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top