我已经创建了一个paypal表单,但我希望在确认并插入所有数据库查询之后重定向paypal信息我希望表单应该自动提交并重定向到paypal所以我使用了一些jQuery这样做但是不幸的是,当我重新加载页面时,他的表格没有提交,任何人都可以帮助我
这是我的代码
<form action="listing.php" method="post">
<input type="hidden" name="business" value="<?php echo $paypal_id; ?>">
<input type="hidden" name="url" value="<?php echo $paypal_id; ?>">
<input type="hidden" name="paypal_url" value="<?php echo $paypal_url; ?>" />
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="Room Rent for <?php echo $data['name']; ?>">
<input type="hidden" name="item_number" value="<?php echo $_SESSION['id']; ?>">
<input type="hidden" name="credits" value="510">
<input type="hidden" name="userid" value="<?php echo $_SESSION['id']; ?>">
<input type="hidden" name="amount" value="<?php echo $total_cost; ?>">
<input type="hidden" name="start_time" value="<?php echo $start_time; ?>" />
<input type="hidden" name="end_time" value="<?php echo $end_time; ?>" />
<input type="hidden" name="agent_id" value="<?php echo $data['agent_id']; ?>" />
<input type="hidden" name="list_id" value="<?php echo $data['id']; ?>" />
<button type="submit" class="btn5 btn-primary btn-sm" name="book">Book Now</button>
</form>
所以让我解释一下我在这里做了什么是我在第一个表单中创建了2个表单我想让用户点击提交当用户提交所有信息保存到数据库后保存它生成一个自动id最后一个id和我希望那个id作为交易ID,所以我发送了这个id到paypal for和paypal没有形式我无法发送信息所以这就是为什么我使用了以下步骤来这样做
<?php
if(isset($_POST['book'])) {
$user_id = $_POST['userid'];
$agent_id = $_POST['agent_id'];
$list_id = $_POST['list_id'];
$business = $_POST['business'];
$item_name = $_POST['item_name'];
$item_num = $_POST['item_number'];
$amount = $_POST['amount'];
$item_num = $_POST['item_number'];
$start_time= $_POST['start_time'];
$end_time = $_POST['end_time'];
$qry_sql = mysqli_query($connection, "INSERT INTO bookings (user_id, agent_id, list_id, booking_date, start_time, end_time, price, status) VALUES ('$user_id', '$agent_id', '$list_id', '".date('d-m-Y')."', '$start_time', '$end_time', '$amount', 'Pending')");
$trans_id = mysqli_insert_id($connection);
if($qry_sql) {
$co_ammount = $amount / 100 * 25;
$agent_ammount = $amount - $co_ammount;
$due_date = date('d-m-Y', strtotime("+2 days"));
$qry_sql1 = mysqli_query($connection, "INSERT INTO financial (agent_id, booking_id, order_date, due_date, total_ammount, agent_ammount, co_ammount, status) VALUES ('$agent_id', '$trans_id', '".date('d-m-Y')."', '$due_date', '$amount', '$agent_amount', '$co_ammount', 'Pending')");
?>
<script>
$('#frmPayPal1').submit();
</script>
<form action="<?php echo $_POST['paypal_url']; ?>" method="post" id="frmPayPal1">
<input type="hidden" name="business" value="<?php echo $business; ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="<?php echo $item_name; ?>">
<input type="hidden" name="item_number" value="<?php echo $trans_id; ?>">
<input type="hidden" name="userid" value="<?php echo $user_id; ?>">
<input type="hidden" name="amount" value="<?php echo $amount; ?>">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="handling" value="0">
<input type="hidden" name="cancel_return" value="http://dev.uparksf.com/cancel.php?tx=<?php echo $trans_id; ?>">
<input type="hidden" name="return" value="http://dev.uparksf.com/success.php">
</form>
<?php } ?>
<?php } ?>
答案 0 :(得分:1)
只需要做一件事,而不是
<script>
$('#frmPayPal1').submit();
</script>
它应该是:
<script>
$(document).ready(function(){
$('#frmPayPal1').submit();
})
</script>
这应该有效!
答案 1 :(得分:0)
将您的提交语句放在表单结束标记之后。 Javascript是程序性的,因此在提交表单之前将表单放在加载之前。