【发布时间】:2015-07-29 14:23:15
【问题描述】:
我有一个带有邮件设置的贝宝监听器,工作正常,但我试图将一个“自定义”变量传递给贝宝,以返回我的 IPN 以更新我的数据库。侦听器正在使用 IPN 模拟器,但我已将其范围缩小到未发送“自定义”信息的注册页面。我无论如何都不会流利地使用 php,下面是我在 paypal 按钮上使用的代码:
<?php
if(!empty($_POST['name']))
{
$name = mysql_real_escape_string($_POST['name']);
$phone = mysql_real_escape_string($_POST['phone']);
$email = mysql_real_escape_string($_POST['email']);
$address = mysql_real_escape_string($_POST['address']);
$date = mysql_real_escape_string(date("Y.m.d"));
$active = mysql_real_escape_string('Active - Not Paid');
$supportrec = isset($_POST['supportboatsyes']);
$support10hpban = isset($_POST['support10hpbanyes']);
$supporttotalban = isset($_POST['supporttotalbanyes']);
$emaillist = isset($_POST['addtoemailyes']);
$volunteer = mysql_real_escape_string($_POST['volunteer']);
$checkusername = mysql_query("SELECT * FROM recreationUsers WHERE Name = '".$name."'");
if(mysql_num_rows($checkusername) == 1)
{
echo "<h1>Error</h1>";
echo "<p>Sorry, you have already registered. <br /> Please contact the site administrator regarding any issues.</p>";
}
else
{
$registerquery = mysql_query("INSERT INTO recreationUsers (Name, Phone, Email, Address, Date_added, Status, Support_all_recreation, Support_10hp_ban, Support_no_boats, Email_list, Volunteer) VALUES('".$name."', '".$phone."', '".$email."', '".$address."', '".$date."', '".$active."', '".$supportrec."', '".$support10hpban."', '".$supporttotalban."', '".$emaillist."', '".$volunteer."')");
if($registerquery)
{
$custom = mysql_real_escape_string($_POST['name']);
echo "<h1>Success, please choose your account type below:</h1>";
echo '<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="6F6YP6CVBRW92" />
<input type="hidden" name="custom" value="$custom" />
<table>
<tr><td><input type="hidden" name="on0" value="Choose a subscription:" />Choose a subscription:</td></tr>
<tr>
<td>
<select name="os0">
<option value="Individual">Individual: $20.00 CAD - Annual</option>
<option value="Family">Family: $50.00 CAD - Annual</option>
</select>
</td>
</tr>
</table>
<input type="hidden" name="currency_code" value="CAD" />
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" 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>';
echo "<p>If you don't have a Paypal account Please Click on the next page \"Pay using your credit or debit card.\"</p>";
}
else
{
echo "<h1>Error</h1>";
echo "<p>Sorry, your registration failed. Please go back and try again.</p>";
}
}
}
else
{
?>
我也试过了:
<input type="hidden" name="custom" value="<?php echo htmlspecialchars($custom); ?>"
和:
<input type="hidden" name="custom" value="<?php echo $custom); ?>"
谁能指导我正确使用这个吗?
【问题讨论】:
-
为什么要在 html 表单值上使用 sql 转义?反斜杠在 html 中完全没有意义,并且是一个常规字符。
-
我正在阅读一个论坛,它对某人有用,对不起,我完全迷路了,我不知道该去哪里。
-
你已经设置了一个变量
$name为什么又$custom你可以使用$name -
所以这应该有效吗?
<input type="hidden" name="custom" value="$custom" />