No value display on next page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mark103
Forum Newbie
Posts: 14
Joined: Sat Sep 20, 2008 9:41 am

No value display on next page

Post by mark103 »

Hi guys,

I need your help. When I entering the value number on the form one-line textbox and when I submits the button, the page redirect me to paypal website but there is no value number when I go to the next page.


Here it is the code:

Code: Select all

<?php
$p = new paypal_class;
$p->add_field('business',  'me@mail.com');
$p->add_field('first_name',  $_POST['first_name']);
$p->add_field('shipping',  '');
$p->add_field('',  'http://www.domain.com/logo.jpg');
$p->add_field('return',  'http://www.domain.com/success.php');
$p->add_field('cancel_return',  'http://www.domain.com/cancelled.php');
$p->add_field('notify_url',  '2');
$p->add_field('cmd',  '_xclick');
$p->add_field('currency_code',  'USD');
$p->add_field('lc',  'US');
$p->add_field('bn',  'toolkit-php');
$p->add_field('no_shipping',  '');
$p->add_field('no_note',  '1');
$p->add_field('cn',  'Comments');
$p->add_field('cs',  '');
$p->add_field('quantity',  '1');
$p->add_field('item_name',  'Add fund to my account');
$p->add_field('amount',  $_POST['deposit.php', formtext1']);
$p->add_field('item_number',  '777');
$p->add_field('undefined_quantity',  '');
$p->add_field('on1',  '');
$p->add_field('os1',  '');
$p->add_field('shipping',  '');
$p->add_field('shipping2',  '');
$p->add_field('handling',  '');
$p->add_field('tax',  ''); 
$p->add_field('custom',  ''); 
$p->add_field('invoice',  ''); 
$p->add_field('first_name',  'test');
$p->add_field('last_name',  '');
$p->add_field('address1',  '');
$p->add_field('address2',  '');
$p->add_field('city',  $_POST['MyTown']);
$p->add_field('state',  '');
$p->add_field('zip',  '');
$p->add_field('login_email',  'me@mail.com');
$p->add_field('night_phone_a',  '');
$p->add_field('night_phone_b',  '');
$p->add_field('night_phone_c',  '');
$p->submit_paypal_post();
$p = new paypal_class;
if ($p->validate_ipn()) {
}
class paypal_class {
var $last_error;
var $ipn_log;
var $ipn_log_file;
var $ipn_response;
var $ipn_data = array();
var $fields = array();
function paypal_class() {
$this->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
$this->last_error = '';
$this->ipn_log_file = 'ipn_log.txt';
$this->ipn_log = true;
$this->ipn_response = '';
$this->add_field('rm', '2');
$this->add_field('cmd', '_xclick');
}
function add_field($field,  $value) {
$this->fields["$field"] = $value;
}
function submit_paypal_post() {
echo "<html>\n";
echo "<head><title>Processing Payment...</title></head>\n";
echo "<body onLoad=\"document.form.submit();\">\n";
echo "<h3>Please wait,  your order is being processed...</h3>\n";
echo "<form method=\"post\" name=\"form\" action=\"".$this->paypal_url."\">\n";
foreach ($this->fields as $name => $value) {
echo "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
}
echo "</form>\n";
echo "</body></html>\n";
}
function validate_ipn() {
$url_parsed=parse_url($this->paypal_url);  
$post_string = ''; 
foreach ($_POST as $field=>$value) { 
$this->ipn_data["$field"] = $value;
$post_string .= $field.'='.urlencode($value).'&'; 
}
$post_string.="cmd=_notify-validate"; // append ipn command
// open the connection to paypal
if(!$fp) {
$this->last_error = "fsockopen error no. $errnum: $errstr";
$this->log_ipn_results(false); 
return false;
} else {
// Post the data back to paypal
fputs($fp,  "POST $url_parsed[path] HTTP/1.1\r\n"); 
fputs($fp,  "Host: $url_parsed[host]\r\n"); 
fputs($fp,  "Content-type: application/x-www-form-urlencoded\r\n"); 
fputs($fp,  "Content-length: ".strlen($post_string)."\r\n"); 
fputs($fp,  "Connection: close\r\n\r\n"); 
fputs($fp,  $post_string . "\r\n\r\n"); 
// loop through the response from the server and append to variable
while(!feof($fp)) { 
$this->ipn_response .= fgets($fp,  1024); 
} 
fclose($fp); // close connection
}
if (eregi("VERIFIED", $this->ipn_response)) {
// Valid IPN transaction.
$this->log_ipn_results(true);
return true; 
} else {
$this->last_error = 'IPN Validation Failed.';
$this->log_ipn_results(false);   
return false;
}
}
function log_ipn_results($success) {
if (!$this->ipn_log) return;  // is logging turned off?
$text = '['.date('m/d/Y g:i A').'] - '; 
// Success or failure being logged?
if ($success) $text .= "SUCCESS!\n";
else $text .= 'FAIL: '.$this->last_error."\n";
 
// Log the POST variables
$text .= "IPN POST Vars from Paypal:\n";
foreach ($this->ipn_data as $key=>$value) {
$text .= "$key=$value,  ";
}
$text .= "\nIPN Response from Paypal Server:\n ".$this->ipn_response;
$fp=fopen($this->ipn_log_file, 'a');
fwrite($fp,  $text . "\n\n"); 
 
fclose($fp);  // close file
}
function dump_fields() {
echo "<h3>paypal_class->dump_fields() Output:</h3>";
echo "<table width=\"95%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">
<tr>
<td bgcolor=\"black\"><b><font color=\"white\">Field Name</font></b></td>
<td bgcolor=\"black\"><b><font color=\"white\">Value</font></b></td>
</tr>"; 
 
ksort($this->fields);
foreach ($this->fields as $key => $value) {
echo "<tr><td>$key</td><td>".urldecode($value)."&nbsp;</td></tr>";
}
echo "</table><br>"; 
}
}

The problem that comes with this line:

Code: Select all

$p->add_field('amount',  $_POST['deposit.php', formtext1']);


I want to display the value number on the next page when I enter the value number on formtext1 in deposit.php.



Please help!!!!!!!!!!



Thanks,
Mark
Paul Arnold
Forum Contributor
Posts: 141
Joined: Fri Jun 13, 2008 10:09 am
Location: Newcastle Upon Tyne

Re: No value display on next page

Post by Paul Arnold »

Code: Select all

 $p->add_field('amount',  $_POST['formtext1']);
I can't see why the url would be in the post variable.
mark103
Forum Newbie
Posts: 14
Joined: Sat Sep 20, 2008 9:41 am

Re: No value display on next page

Post by mark103 »

Thanks for your reply, do you know how to situation my problem and get this resolve??





I have tried in a different way where the form are coming from (form-sign.php). The methods I tried into situations didn't going to works.




Hope you can help!!!!!!!!!


Thanks,
Mark
mark103
Forum Newbie
Posts: 14
Joined: Sat Sep 20, 2008 9:41 am

Re: No value display on next page

Post by mark103 »

nobody??
mark103
Forum Newbie
Posts: 14
Joined: Sat Sep 20, 2008 9:41 am

Re: No value display on next page

Post by mark103 »

CAN SOMEONE <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> HELP ME PLEASE
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: No value display on next page

Post by Stryks »

Someone did smurf help you ... you just don't seem to have read or understood what he said.

If your form has a field named textbox1 and you want to get that value, you access it on the script the form is posted to with $_POST['textbox1'].

Your example ...

Code: Select all

$p->add_field('amount',  $_POST['deposit.php', formtext1']);
 
... doesn't do that does it?

For some reason you have a filename in there. Then you have a comma, then an uncommented piece of text and a lone single quote.

Why? You haven't done that with ...

Code: Select all

$p->add_field('first_name',  $_POST['first_name']);
... but it's all good there.

So, the advice is to remove the filename and the comma, and just have the field name in a matched set of single quotes. Much like with 'first_name'. However, I'm wondering if what you are REALLY asking is "how can I get the amount value from a different form" ... the short answer to which is "You can't";

So make the change suggested, and if it still doesn't work, post back with what it is that you are trying to do, and where you are trying to get the information from.

Cheers
mark103
Forum Newbie
Posts: 14
Joined: Sat Sep 20, 2008 9:41 am

Re: No value display on next page

Post by mark103 »

LOOK! I have tried in both methods and they didn't works in that way. I don't think you know what i am doing. I am trying to input the value number on formtext1 in deposit.php and when I redirect to paypal site, i want the value to display next to the amount where i entered the value on formtext1 from deposit.php. Hope you get this now?????????




Thanks,
Mark
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: No value display on next page

Post by onion2k »

Does it work if you set it to specific number? Eg

Code: Select all

$p->add_field('amount',  10);
If it does then the problem must be $_POST['deposit.php', formtext1'] not containing the correct value. Fairly obviously "'deposit.php', formtext1'" is not a valid key. It seems, on the face of it, that it ought to be $_POST['formtext1'] but as you've tried that and it failed there must be something else going wrong. Could you post the HTML form from the preceding page?
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: No value display on next page

Post by Stryks »

mark103 wrote:I don't think you know what i am doing.
I have a pretty good idea of what you're trying to achieve, but what is more important is that I can see exactly what you're doing wrong. You'd be amazed how often fixing something that is wrong makes the script right. But I digress ...

Have you actually tried the exact line from the code snippet by Paul Arnold? It is at the very least a valid use of a $_POST value. You gave an odd response that seemed to indicate that you had changed the file name you posted from, but nothing about having actually used his exact code ... I'm not sure. But did you try using that exact line? Did you get the same result?

Assuming you have tried that, then what onion2k suggests is probably the best approach. Hard code a value and see if it gets set. If it does then you've narrowed the issue down to where you're getting the data, as opposed to how you're setting it. That is where the previous HTML form comes in ... it gives us an idea of what index to use to get the data out of $_POST.

Anyhow, give it a shot and let us know what results you get.
Post Reply