0

我想要完成的只是允许用户从下拉列表中选择他们的用户名,然后选择他们想要使用该帐户购买的物品。一个问题是,当单击 PayPal 按钮时,用户名未存储在自定义字段中,但交易顺利进行。

支付宝按钮代码:

    // Get information from database
    $result = mysql_query("SELECT username FROM account WHERE mainusername='".$username."'");

while($row = mysql_fetch_array($result)) {

echo "<option>".$row['username']."</option>";

}
?>
</select>
</tr>
</td>
<tr>
<td>
<input type="hidden" name="on0" value="itemforsale">
<select name="os0">
    <option value="shirt">shirt $5.55 USD</option>
    <option value="short">short $31.55 USD</option>
    <option value="skirt">skirt $62.75 USD</option>
</select>
</td>
</tr>
</table>
<br />
<input type="hidden" name="custom" value="
<?php 
if(isset($_POST['getusername'])) {

$getusername = $_POST['getusername']; 
echo "".$getusername."";

}
?>
">
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
4

1 回答 1

0

您在遍历用户名时忘记设置“选项”值。它应该看起来像:

$result = mysql_query("SELECT username FROM account WHERE mainusername='".$username."'");
while($row = mysql_fetch_array($result)) {
     echo "<option value='".$row['username']."'>".$row['username']."</option>";
}

我还建议为此使用 jQuery。该页面不必重新加载。

    <script type="text/javascript">
        $(document).ready(function() { 
            $("#username_select").change(function() { 
                $("#paypal_custom").val($(this).val());
            });
        });
    </script>

将用户名 ID 设置为“username_select”,将 Paypal“自定义”隐藏输入 ID 设置为“paypal_custom”。

于 2013-03-27T14:29:15.647 回答