adman4054 Posted May 19, 2016 Share Posted May 19, 2016 How do I place an echo statement from an include page in the proper area of the page I'm calling it from? I need it to appear within two div tags. Right now it just prints at the bottom of the page. <div id="content">echo content<div id="main"> Thanks for any assistance Quote Link to comment https://forums.phpfreaks.com/topic/301215-echo-from-an-include-page/ Share on other sites More sharing options...
benanamen Posted May 19, 2016 Share Posted May 19, 2016 Try posting the code you are using. Quote Link to comment https://forums.phpfreaks.com/topic/301215-echo-from-an-include-page/#findComment-1533088 Share on other sites More sharing options...
requinix Posted May 19, 2016 Share Posted May 19, 2016 PHP executes in the order you tell it to. If you want the output to appear on a certain spot on the page then you need code at that spot which causes the output. Could simply be a matter of moving the include statement, but like benanamen said you should post your code. Quote Link to comment https://forums.phpfreaks.com/topic/301215-echo-from-an-include-page/#findComment-1533089 Share on other sites More sharing options...
adman4054 Posted May 19, 2016 Author Share Posted May 19, 2016 First box of code is the include file, I would like the two echo statements to be between the divs in the second box. $api_login = $_SESSION['LOGIN']; $transaction_key = $_SESSION['TRANSKEY']; $payment = new AuthnetAIM( $api_login, $transaction_key, true); $payment->setTransaction($creditcard, $expiration, $total, $cvv, $invoice); $payment->setParameter("x_duplicate_window", 180); $payment->setParameter("x_customer_ip", $_SERVER['REMOTE_ADDR']); $payment->setParameter("x_email", $email); $payment->setParameter("x_email_customer", FALSE); $payment->setParameter("x_first_name", 'test'); $payment->setParameter("x_last_name", 'hello'); $payment->setParameter("x_address", $address); $payment->setParameter("x_city", $city); $payment->setParameter("x_state", $state); $payment->setParameter("x_zip", $zipcode); $payment->setParameter("x_description", $product); $payment->process(); if ($payment->isApproved()) { // if success, return array $return_array['amount'] = $total; $return_array['Email'] = $email; if ( isset( $_POST['anonymous'] ) && $_POST['anonymous']==1) { $return_array['anonymous'] = true; } else { $return_array['first_name'] = $firstname; $return_array['last_name'] = $lastname; } $return_array['transaction_nonce'] = $_POST['n']; $return_array['success'] = true; } else if ($payment->isDeclined()) { // Get reason for the decline from the bank. This always says, // "This credit card has been declined". Not very useful. $reason = $payment->getResponseText(); $return_array['error_msg'] = __( 'This credit card has been declined. Please use another form of payment.', 'pfund' ); } else if ($payment->isError()) { // Capture a detailed error message. No need to refer to the manual // with this one as it tells you everything the manual does. $return_array['error_msg'] = $payment->getResponseMessage(); // We can tell what kind of error it is and handle it appropriately. if ($payment->isConfigError()) { // We misconfigured something on our end. //$return_array['error_msg'] .= " Please notify the webmaster of this error."; } else if ($payment->isTempError()) { // Some kind of temporary error on Authorize.Net's end. // It should work properly "soon". $return_array['error_msg'] .= __( ' Please try your donation again.', 'pfund' ); } else { // All other errors. } } } catch (AuthnetAIMException $e) { $return_array['error_msg'] ="There was an error processing the transaction. Please report this CATCH error to administration.<br><br>Error: " . $e->__toString(); } echo "<br /><div align='left'>Your changes have been saved and your card charged $<font color='#ff0000'>" .$return_array['amount']."</font></div>"; echo "<br /><div align='left'>Error message of some type$<font color='#ff0000'>" .$return_array['error_msg']."</font></div>"; <div id="wrapper"> <div id="header-adt" class="content-width"> <div data-oas-id="x01" data-oas-breakpoint="desktop" class="oas-ad desk tablet-hidden mobile-hidden"></div> <div data-oas-id="x01" data-oas-breakpoint="tablet" class="oas-ad tablet large-hidden mobile-hidden"></div> <div data-oas-id="x01" data-oas-breakpoint="mobile" class="oas-ad mobile"></div> </div> <div id="content"> <div id="main"> <?php //display errors or display success message Thanks for taking a look Quote Link to comment https://forums.phpfreaks.com/topic/301215-echo-from-an-include-page/#findComment-1533090 Share on other sites More sharing options...
benanamen Posted May 19, 2016 Share Posted May 19, 2016 (edited) You haven't shown how and where you are including the code. Nevertheless, change those echos to variables, i.e $var1, $var2 and then echo those variables where you want them AFTER the include file line wherever that is. Your include code is bad. You're missing something, like the Try. Edited May 19, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/301215-echo-from-an-include-page/#findComment-1533091 Share on other sites More sharing options...
adman4054 Posted May 21, 2016 Author Share Posted May 21, 2016 I just cant get this to work. So I change the echo to a variable on the include page. but when I place the variable on the page where I need it to go, it doesn't show and I've been googling for hours. editListing.php page has the include payment.php, I created $var1 = $return_array['amount']; on the included payment.php, but when I try placing the echo $var1 on the editListing.php it doesn't work, what am I missing? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/301215-echo-from-an-include-page/#findComment-1533145 Share on other sites More sharing options...
ginerjm Posted May 21, 2016 Share Posted May 21, 2016 show us the corrected code so we can see really see the problem. Quote Link to comment https://forums.phpfreaks.com/topic/301215-echo-from-an-include-page/#findComment-1533146 Share on other sites More sharing options...
adman4054 Posted May 21, 2016 Author Share Posted May 21, 2016 This is the include page. payment.php I added the $var at the end of the code box. require('../authNet/AuthnetAIM.class.php'); $queryInvoiceId = mysql_query("INSERT INTO invoices (id) VALUES(NULL)"); $invoiceId = mysql_insert_id(); //echo $invoiceId."<br>"; $invoiceId = "DIR-" . sprintf('%1$09d', $invoiceId); //echo $invoiceId;die(); //define variables to send $cardNumber = strip_tags($_POST["CCnum"]); $expirationDate = strip_tags($_POST['CCexpireMonth']) . "-" . strip_tags($_POST['CCexpireYear']); //$amount = $priceToCharge; //sent above $cvv = strip_tags($_POST['CC3digit']); $email = $_SESSION['listContactEmail']; $company = $_SESSION['listCompName']; $company = str_replace("&", " ", $company); $company = str_replace("'", " ", $company); $firstName = $_SESSION['contact_first_name']; $firstName = str_replace("'", " ", $firstName); // $firstName = htmlspecialchars($firstName, ENT_QUOTES); $lastName = $_SESSION['contact_last_name']; $lastName = str_replace("'", " ", $lastName); // $lastName = htmlspecialchars($lastName, ENT_QUOTES); $address = $_SESSION['listAdd1']; $city = $_SESSION['listCity']; $state = $_SESSION['listState']; $zip = $_SESSION['listZip']; $country = $_SESSION['listCountry']; $description = "Directory Listing Payment - Listing: " . $company; /////////////////code try { $email = $email; $product = 'Directory listing RPN'; $firstname = $firstname; $lastname = $lastName; $address = $address; $city = $city ; $state = $state; $zipcode = $zip; $creditcard = $cardNumber; $expiration = $expirationDate; $total = $amount; $cvv = $cvv; $invoice = $invoiceId ; $api_login = $_SESSION['LOGIN']; $transaction_key = $_SESSION['TRANSKEY']; $payment = new AuthnetAIM( $api_login, $transaction_key, true); $payment->setTransaction($creditcard, $expiration, $total, $cvv, $invoice); $payment->setParameter("x_duplicate_window", 180); $payment->setParameter("x_customer_ip", $_SERVER['REMOTE_ADDR']); $payment->setParameter("x_email", $email); $payment->setParameter("x_email_customer", FALSE); $payment->setParameter("x_first_name", 'test'); $payment->setParameter("x_last_name", 'hello'); $payment->setParameter("x_address", $address); $payment->setParameter("x_city", $city); $payment->setParameter("x_state", $state); $payment->setParameter("x_zip", $zipcode); $payment->setParameter("x_description", $product); $payment->process(); if ($payment->isApproved()) { // if success, return array $return_array['amount'] = $total; $return_array['Email'] = $email; if ( isset( $_POST['anonymous'] ) && $_POST['anonymous']==1) { $return_array['anonymous'] = true; } else { $return_array['first_name'] = $firstname; $return_array['last_name'] = $lastname; } $return_array['transaction_nonce'] = $_POST['n']; $return_array['success'] = true; } else if ($payment->isDeclined()) { // Get reason for the decline from the bank. This always says, // "This credit card has been declined". Not very useful. $reason = $payment->getResponseText(); $return_array['error_msg'] = __( 'This credit card has been declined. Please use another form of payment.', 'pfund' ); } else if ($payment->isError()) { // Capture a detailed error message. No need to refer to the manual // with this one as it tells you everything the manual does. $return_array['error_msg'] = $payment->getResponseMessage(); // We can tell what kind of error it is and handle it appropriately. if ($payment->isConfigError()) { // We misconfigured something on our end. //$return_array['error_msg'] .= " Please notify the webmaster of this error."; } else if ($payment->isTempError()) { // Some kind of temporary error on Authorize.Net's end. // It should work properly "soon". $return_array['error_msg'] .= __( ' Please try your donation again.', 'pfund' ); } else { // All other errors. } } } catch (AuthnetAIMException $e) { $return_array['error_msg'] ="There was an error processing the transaction. Please report this CATCH error to administration.<br><br>Error: " . $e->__toString(); } $var1 = $return_array['amount']; This is the editListing.php page where I have tried to echo the var. I have tried it in several places on the editListing.php page. <div id="wrapper"> <div id="header-adt" class="content-width"> <div data-oas-id="x01" data-oas-breakpoint="desktop" class="oas-ad desk tablet-hidden mobile-hidden"></div> <div data-oas-id="x01" data-oas-breakpoint="tablet" class="oas-ad tablet large-hidden mobile-hidden"></div> <div data-oas-id="x01" data-oas-breakpoint="mobile" class="oas-ad mobile"></div> </div> <div id="content"> <div id="main"> <?php echo "$var1"; //display errors or display success message if(isset($_POST['saveListing'])){ if($_POST['payment']=='creditcard'){ echo "<br /><br /><div align='center'><font color='#ff0000'>Changes saved and your credit card has been charged ".'$' .$mybillingamount."</font></div>\n"; } elseif($_POST['payment']=='check'){ echo "<br /><br /><div align='center'><font color='#ff0000'>Changes saved, payment by check ".'$' .$mybillingamount."</font></div>\n"; } else{echo "<br /><br /><div align='center'><font color='#ff0000'>Changes saved, but must be approved by the administrator</font></div>\n";} Thanks for looking Quote Link to comment https://forums.phpfreaks.com/topic/301215-echo-from-an-include-page/#findComment-1533147 Share on other sites More sharing options...
ginerjm Posted May 22, 2016 Share Posted May 22, 2016 So hard to make any sense of this. I'm assuming that the line "echo $var1" is the line in question. And that it is not showing up in 'main' div area. Question - why are you doing all this output when you haven't received the rest of the POST data fields? Seems backwards to be worrying about your output when you haven't even analyzed the input yet. Good practice says to separate the bulk of your html from your php. Same for the JS code too. Grab all the inputs, work with them, build the dynamic output into php vars and THEN do the output of your static html (doctype, metas, head, scripts,styles and body tags) and then place those php vars where they need to be, ALL at the end of the script. First things first and last things last. Makes much more sense logically as you read thru the script and is much easier to maintain down the road. PS - you should really learn some css and get all that outdated styling out of your html tags. Quote Link to comment https://forums.phpfreaks.com/topic/301215-echo-from-an-include-page/#findComment-1533158 Share on other sites More sharing options...
mac_gyver Posted May 22, 2016 Share Posted May 22, 2016 i'm going to guess, since the OP has still has not shown the include statement, that he is using a URL, rather than a file system path, to include the file and the variables don't exist, since they are in a completely separate process on the web server. Quote Link to comment https://forums.phpfreaks.com/topic/301215-echo-from-an-include-page/#findComment-1533159 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.