The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

2 Pages V < 1 2  
Reply to this topicStart new topic
> PayPal checkout and PHP
tudsy
post Oct 15 2022, 09:36 PM
Post #21


Serious Coder
*****

Group: Members
Posts: 252
Joined: 30-September 14
Member No.: 21,611



Hi

Thanks for that.

Process1.php (txt) inserts data in a database from a form (form1.php). It also should produce a paypal button for users to pay with paypal. I ran php -l process1.php and found there to be no syntax errors.

The latest version of process1.txt is that I removed the try-catch block to make it simpler (attached).


Any help would be appreciated.









QUOTE(CharlesEF @ Oct 7 2022, 05:46 AM) *

Exactly what problem are you having? I thought it was about the shutdown part. Describe the problem, what you expect from your code and what the code actually does.

Attached File  process1.txt ( 3.47k ) Number of downloads: 919
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Oct 16 2022, 01:30 AM
Post #22


Programming Fanatic
********

Group: Members
Posts: 1,996
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I don't think I will be able to help this time. I have helped people with Paypal problems in PHP but never Javascript. You would do better to ask at the Paypal Community Support Forum here.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Oct 16 2022, 05:27 PM
Post #23


Programming Fanatic
********

Group: Members
Posts: 1,996
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Also, I didn't see any button in your HTML. I know nothing about Paypal and Javascript but don't you need a button before you can render it?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
tudsy
post Nov 17 2022, 09:31 AM
Post #24


Serious Coder
*****

Group: Members
Posts: 252
Joined: 30-September 14
Member No.: 21,611



Hi

After talking to the PayPal community, I have settled on the form below:


<?php



if(isset($_POST['Person']) && isset($_POST['Graphic']) && isset($_POST['Price'])){

$person=$_POST['Person'];
$graphic = $_POST['Graphic'];
$Price = $_POST['Price'];

}

$url = "https://ecovib2d.com.au/workfromhome/yourart/".$person."/Graphic/".$graphic;

?>


<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<input type='hidden' name='business' value='ecovib2d@live.com' />

<input type="hidden" name="upload" value="1">

<INPUT TYPE="hidden" NAME="return" value= "<?php echo $url; ?>">

<INPUT TYPE="hidden" NAME="currency_code" value="AUD">

<input type='hidden' id = 'Cost' name='Price' value='<?php echo $Price; ?>' />
<input type='hidden' id = 'pic' name='Graphic' value='<?php echo $graphic; ?>' />
<input type="hidden" id='Person' name='Artist' value ='<?php echo $person; ?>'/>

<label for='Age_of_Subscriber'>Enter your Age (in years - Privacy purposes):</label>
<input type='number' id='Age_of_Subscriber' name='Age' size ='3' required min='0' max='200' />
<br>
<br>
<label for='Full_Name'>Enter your First Name:</label>
<input type='text' id='FirstName' name='First_Name' required />
<br>
<br>
<label for='Full_Name'>Enter your Last Name:</label>
<input type='text' id='Surname' name='Last_Name' required />
<br>
<br>

<label for='email'>Enter your Email address:</label>
<input type='email' id='email' name='Email_Address' size='30' placeholder ='Your Email Address' required />
<br>
<br>





<p>
View our Terms of Service (https://ecovib2d.com.au/workfromhome/TOC/website_terms_and_conditions_of_use) and
Privacy Policy (https://ecovib2d.com.au/workfromhome/privacy/privacypolicy.php).</p>

<br>
<br>

<!-- Saved buttons use the "secure click" command -->
<input type="hidden" name="cmd" value="_xclick">

<input type="hidden" name="item_name" value="Your Graphic - <?php echo $graphic; ?>" >


<input type="hidden" name="amount" value="<?php echo $Price; ?>">

<INPUT TYPE="hidden" name="address_override" value="1">

<!-- Saved buttons display an appropriate button image. -->
<input type='image' name='submit' border='0' src='https://www.paypalobjects.com/webstatic/en_US/i/btn/png/btn_buynow_107x26.png' alt='Buy Now' />
<img alt='' src='https://paypalobjects.com/en_US/i/scr/pixel.gif' width='1' height='1' />

</form>

The problem now is that I am trying to execute a php script at the same time the submit button is clicked.
Do I need Ajax for this ?

Thanks.

<?php

if($_SERVER['REQUEST_METHOD'] ===' POST'){

if(isset($_POST['submit'])){



include "process.php";

}
}

?>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Nov 17 2022, 02:19 PM
Post #25


Programming Fanatic
********

Group: Members
Posts: 1,996
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



The for attribute of a label should point to the id attribute of the element, not the name attribute. Both labels for first and last name need to be changed.

Also, this:
CODE
if(isset($_POST['Person']) && isset($_POST['Graphic']) && isset($_POST['Price']))

Could be:
CODE
if(isset($_POST['Person'], $_POST['Graphic'], $_POST['Price']))


Do you want the page to be visible while the PHP script runs? If yes, then you need to use AJAX. You would also need a place in the page to display the results of the PHP script. I wouldn't use a submit button for this. I would use a normal button that calls the Javascript function that runs the AJAX script. You may need to add logic to your PHP script to prevent multiple payments.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Nov 17 2022, 04:33 PM
Post #26


Programming Fanatic
********

Group: Members
Posts: 1,996
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



If you don't want to stay on the same page during the payment process then don't use AJAX. Use a submit button but use your PHP script location in the form action attribute. Now you can show the results of the payment process in a new page.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
tudsy
post Nov 26 2022, 04:41 AM
Post #27


Serious Coder
*****

Group: Members
Posts: 252
Joined: 30-September 14
Member No.: 21,611



Hi

Hi

I have solved the problem of writing data to a database after the submit button is clicked on a form.

<script type="text/javascript">

$(document).ready(function () {
$("#submit").click(function () {
$.ajax({
type: "POST",
url: "process.php",
data:{

Graphic: $('#pic').val(),
Person: $('#Person').val(),
Price: $('#Cost').val(),
Age: $('#Age_of_Subscriber').val(),
First_Name: $('#FirstName').val(),
Last_Name: $('#SurName').val(),
Email_Address: $('#Email').val(),
}

})

});
});

</script>

Thanks.

Adrian
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

2 Pages V < 1 2
Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 13th December 2024 - 10:10 PM