Hearnah Posted April 5, 2008 Share Posted April 5, 2008 hi! I'm Danny :-) Basically, i have a small problem, where I have a paypal button which goes to a payment screen (the basic button) But what i would like to do, is when the button is clicked, a script triggers to add into my database, i can do all it apart from work out how to get the script to trigger, and still go to the paypal link For instance [link] /\ / \ [add to database] \ [go to paypal for payment] Thanks in advance! Dan Link to comment https://forums.phpfreaks.com/topic/99725-solved-im-sure-this-should-be-simple-but-i-cant-work-it-out/ Share on other sites More sharing options...
uniflare Posted April 5, 2008 Share Posted April 5, 2008 use header(); redirect, or if the button is a POST form button, you may need to use javascript as im not sure 10% but i dont think php can POST variables like a browser... (dont quote me on that though ) Link to comment https://forums.phpfreaks.com/topic/99725-solved-im-sure-this-should-be-simple-but-i-cant-work-it-out/#findComment-510115 Share on other sites More sharing options...
Hearnah Posted April 5, 2008 Author Share Posted April 5, 2008 thanks very much uniflare perfect! its redirecting AND its adding into the database Link to comment https://forums.phpfreaks.com/topic/99725-solved-im-sure-this-should-be-simple-but-i-cant-work-it-out/#findComment-510140 Share on other sites More sharing options...
Hearnah Posted April 5, 2008 Author Share Posted April 5, 2008 Well it's sort of working, it's adding into the database and it's also redirecting to paypal, but it's not taking the $_POST with it right at the top <?php header("Location: https://www.paypal.com/cgi-bin/webscr"); include("include/session.php"); ?> then where it grabs all from the submitted page <?php $cmd = mysql_escape_string($_POST['cmd']); $encrypted = mysql_escape_string($_POST['encrypted']); $cdomain = mysql_escape_string($_POST['cdomain']); $sdomain = mysql_escape_string($_POST['sdomain']); $result = mysql_query("INSERT into domains (username, active, sdomain, cdomain) VALUES ('$session->username','n','$sdomain','$cdomain')"); ?> But i'm not sure how to now send $cmd and $encrypted with header('Location: https://www.paypal.com/cgi-bin/webscr'); Link to comment https://forums.phpfreaks.com/topic/99725-solved-im-sure-this-should-be-simple-but-i-cant-work-it-out/#findComment-510144 Share on other sites More sharing options...
uniflare Posted April 5, 2008 Share Posted April 5, 2008 you can either use javascript quite complicated or you can use this (i just found this snippet): <?php $url = 'Location: https://www.paypal.com/cgi-bin/webscr'; $fields = array( 'cmd'=>urlencode($_POST['cmd']), 'encrypted'=>urlencode($_POST['encrypted']) ); //url-ify the data for the POST $fields_string = null; foreach($fields as $key=>$value){ $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); //execute post $result = curl_exec($ch); //close connection curl_close($ch); ?> FYI This uses a php extension called libcurl. You may have to download/enable this extension by going into php.ini and find/add the following line: [php_CURL] extension=php_curl.dll if it exists make sure it reads exactly like the above example. --------- there may be simpler solutions that paypal may have thought of. like using GET variables instead of POST. and there may be a solution like above that does not need any non-default extensions like libcurl. hope this helps, Link to comment https://forums.phpfreaks.com/topic/99725-solved-im-sure-this-should-be-simple-but-i-cant-work-it-out/#findComment-510174 Share on other sites More sharing options...
Hearnah Posted April 5, 2008 Author Share Posted April 5, 2008 thanks very much mate Link to comment https://forums.phpfreaks.com/topic/99725-solved-im-sure-this-should-be-simple-but-i-cant-work-it-out/#findComment-510189 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.