1

I am trying to store a variable in a database when the user clicks the submit button. However, as my submit button is inside of a PHP variable when I am using isset, it doesn't work. Is there another solution or a trick to that?

$pp_checkout_btn .= '<form id="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input name="terms"  type="checkbox" required value="agree" form="paypal"  /><label>Agree with terms & Conditions *</label>
    <input type="submit" name="submit1" id="changebutton" value="ΕΠΙΒΕΒΑΙΩΣΗ ΠΑΡΑΓΓΕΛΙΑΣ"  /></form>';

 if(isset($_POST['submit1'])){
//update orders to accept terms
$updatesql=mysql_query("UPDATE orders SET terms='agree' WHERE checkout_id='$checkout_id'") or die(mysql_error());  }
3
  • 1
    That form posts to paypal.com, you will never see the request. Check the PayPal developer manual on how to integrate it with your site. Commented Apr 10, 2015 at 13:50
  • exactly what you want to save in to the database? Commented Apr 10, 2015 at 13:56
  • Unless you echo or print $pp_checkout_btn, it doesn't exist in the HTML document. I didn't see an echo or print. Commented Apr 10, 2015 at 14:37

2 Answers 2

2

First of all double check your 'action' in the form if it's correct and your if isset statement has to look like this: if(isset($_POST['submit1'])) because form method is POST

Sign up to request clarification or add additional context in comments.

Comments

1

you can call an js function at onsubmit event in ur form. In your function send an ajax request to a PHP page that saves the data u need to save.

I am assuming ur echoing the variable in a HTML page.

<form id="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="return myFunction()" name="paypal" >
<input name="terms"  type="checkbox" required value="agree" form="paypal"  /><label>Agree with terms & Conditions *</label>
<input type="submit" name="submit1" id="changebutton" value="ΕΠΙΒΕΒΑΙΩΣΗ ΠΑΡΑΓΓΕΛΙΑΣ"  /></form>'

now the function:

<script>
function myFunction(){
var str= document.forms["paypal"]["terms"].value;
var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

        }
    }
    xmlhttp.open("GET", "save.php?q=" + str, true);
    xmlhttp.send();
}
</script>

now save.PHP

<?php
if(isset($_GET['q'])){
 //your update query  
 }
  ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.