0

好的,我敢肯定很多人已经问过这个问题,但我还没有看到任何真正明确的答案。我需要捕获一个我已经有值的变量......这是我的例子:

<?php

$data_p = mysql_query("SELECT * FROM `dreams`") or die(mysql_error());

while($info = mysql_fetch_array( $data_p )) {
    <table>
        <tr>
            <td><?php echo $info['first']; ?> <?php echo $info['last']; ?></td>
            <td><?php echo $info['city']; ?> <?php echo $info['state']; ?></td>
            <td><?php echo $info['dream']; ?></td>
            <td>$<?php echo $info['donation_goal']; ?></td>
            <td>
                <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
                <input type="hidden" name="cmd" value="_s-xclick">
                <input type="hidden" name="hosted_button_id" value="2HGLK2WGELUNG">
****************<input type="hidden" name="dream_id" value="<?php echo $info['dream_id']; ?>">
                <input type="image" src="images/donatebutton.png" id="donate" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
                <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
                </form>
            </td>
        </tr>
    </table
}

这显示如下:

http://www.dreamsurreal.com/images/example.jpg

带有所有* *的行是我遇到麻烦的地方。

我在 paypal.com 中创建了按钮,但我自己添加了*行。

我需要将此变量传递给贝宝,以便当我的数据库通过 ipn.php 更新时。这里是 ipn.php 的 MYSQL 更新区:

// add this order to a table of completed orders
    $payer_email = mysql_real_escape_string($_POST['payer_email']);
    $mc_gross = mysql_real_escape_string($_POST['mc_gross']);
    $dream_id = $_POST['dream_id'];
    $sql = "INSERT INTO orders VALUES 
            (NULL, '$txn_id', '$payer_email', '$mc_gross', '$dream_id')";

但由于某种原因,即使我添加了 $dream_id = $_POST['dream_id'] 并且还将 $dream_id 添加到 mysql 插入的 INSERT 部分,它并没有插入实际变量,它只是使其为 0。

我希望我对每个人都足够清楚,我能否就如何使其正常工作获得一些帮助。

4

2 回答 2

0

改变

$dream_id = $_POST['dream_id'];

$dream_id = (int)$_POST['dream_id'];

如果您仔细观察(如果我没记错的话),在 PayPal 的自定义值字段的末尾会有一个点。将变量类型转换为整数可解决此问题并防止SQL 注入您可以在此处阅读有关 PHP 类型转换的更多信息。

于 2013-06-22T23:31:40.783 回答
0

得到它的工作每个人......好吧,这就是它的完成方式:

这是我们没有添加变量的按钮脚本....

    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="2HGLK2WGELUNG">
    <input type="image" src="images/donatebutton.png" id="donate" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>

将此行添加到我们的表单中......

<input type="hidden" name="item_number" value="<?php echo $MY_VARIABLE; ?>">

将 $MY_VARIABLE 替换为您自己的变量。

我们按钮的新代码看起来像

    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="2HGLK2WGELUNG">
    <input type="hidden" name="item_number" value="<?php echo $MY_VARIABLE; ?>">
    <input type="image" src="images/donatebutton.png" id="donate" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>

之后,在您的 ipn.php 中更改此区域

// add this order to a table of completed orders
    $payer_email = mysql_real_escape_string($_POST['payer_email']);
    $mc_gross = mysql_real_escape_string($_POST['mc_gross']);
    $sql = "INSERT INTO orders VALUES 
            (NULL, '$txn_id', '$payer_email', '$mc_gross')";

将这些添加到其中(我使用的是整数,所以我只是确保它的类型正确)

$MY_VARIABLE = (int)$_POST['item_number'];

$sql = "INSERT INTO orders VALUES 
    (NULL, '$txn_id', '$payer_email', '$mc_gross', '$MY_VARIABLE')";

经过我们所有的修复后,整个区域应该如下所示:

    // add this order to a table of completed orders
    $payer_email = mysql_real_escape_string($_POST['payer_email']);
    $mc_gross = mysql_real_escape_string($_POST['mc_gross']);
    $dream_id = (int)$_POST['item_number'];
    $sql = "INSERT INTO orders VALUES 
            (NULL, '$txn_id', '$payer_email', '$mc_gross', '$dream_id')";

我希望这一切都会有所帮助,谢谢您的宝贵时间。

于 2013-06-23T21:13:23.563 回答