从onclick启动PHP函数

时间:2018-01-12 00:59:02

标签: php forms button paypal

我有一个PayPal按钮,我需要说"售罄"点击之后。当按钮单击购物车时,我需要运行PHP代码,添加" M1"到文件" trackOrder.txt"。然后它检查文件中的字符串" M1"。我将有其他按钮也会记录到这个文件。

我需要帮助将它们结合起来以便它起作用。我目前正在启动onmouseover进行测试。

<!--Calls Javascript test function-->
<form onmouseover="javascript:test()"; target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">        
    <input type="hidden" name="business" value="XXXXXXXXXXXXX">
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="add" value="1">
    <input type="hidden" name="item_name" value="Men Accessory 1">
    <input type="hidden" name="amount" value="5.00">            
    <input type="hidden" name="currency_code" value="USD">
    Shipping Options:<br/>
    <select name="handling_cart">
        <option value="0.00">Free Local Pickup at our store</option>
        <option value="3.00">Standard Shipping - $3.00</option>
    </select>
    <br/>1 available</br>
    <input type="image" name="submit" src="http://charitysboutique.com/webpics/addtocart.gif" alt="Add to Cart">
    <img alt="" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif">
</form>

<?php
    function run(){
        $purchasedItem = "M1\n";
        $trackFile = fopen("trackOrder.txt", "a+");
        $txt = $purchasedItem;
        fwrite($trackFile, $txt);
        fclose($trackFile);
        echo "Finished";
    }
?>
<!--Calls PHP run function--> 
<script>
    function test() {   
        <?php run();?>
        alert("function test has been called")
    }
</script>

<!--open and read file-->
<?php
    $trackFile = fopen("trackOrder.txt", "r");
    if( strpos(file_get_contents("trackOrder.txt"),"M1") !== false) {
        echo "Found text";
    }
    fclose($trackFile);
?>

0 个答案:

没有答案