我将信息插入到MySQL表中,我只运行一个INSERT查询,但是当我检查时,记录在表中显示两次。基本上,我将一个作业存储在temp_job表中,其中包含信息,直到用户决定要继续在PayPal上付款为止。然后将它们转移到处理付款的页面,并使用以下代码将用户发送到PayPal:
session_start();
$id = $_GET['id'];
$sql_temp = "SELECT * FROM temp_job WHERE id = '$id'";
$result_temp = $mysqli->query($sql_temp);
$row_temp = mysqli_fetch_array($result_temp);
$company_name = $row_temp['company_name'];
$date_registered = $row_temp['date_registered'];
$date_submitted = $row_temp['date_submitted'];
$job_title = $row_temp['job_title'];
$job_description = $row_temp['job_description'];
$salary = $row_temp['salary'];
$industry_sector = $row_temp['industry_sector'];
$number_people = $row_temp['number_people'];
$payment_received = $row_temp['payment_received'];
$sql_insert = "
INSERT INTO pending_jobs
(company_name, date_registered, date_submitted, job_title, job_description, salary, industry_sector, number_people, payment_received)
VALUES ('$company_name', '$date_registered', '$date_submitted', '$job_title', '$job_description', '$salary', '$industry_sector', '$number_people', '$payment_received')";
$result_insert = $mysqli->query($sql_insert);
$sql_pending = "SELECT * FROM pending_jobs WHERE job_title = '$job_title' AND job_description = '$job_description'";
$result_pending = $mysqli->query($sql_pending);
$row_pending = mysqli_fetch_array($result_pending);
$pending_id = $row_pending['id'];
//TRANSFER TO PAYPAL
echo "
<div id='redirect' style='padding-top:20px;text-align:center;width:922px;'>
You are being redirected...<br /><br />
<span style='font-size:9px;'>If you are not redirected, click the button below:</span><br />
<form id='form' name='paypal' action='https://www.paypal.com/cgi-bin/webscr' method='post'>
<input type='hidden' value='_xclick' name='cmd'>
<input type='hidden' value='test@test.com' name='business'>
<input type='hidden' value='This is the job title - ".$job_title."' name='item_name'>
<input type='hidden' value='352.36' name='amount'>
<input type='hidden' value='http://www.testsite.com/success.php?id=".$pending_id."' name='return'>
<input type='hidden' value='http://www.testsite.com/cancel.php?id=".$id."' name='cancel_return'>
<input type='hidden' value='USD' name='currency_code'>
<input type='hidden' value='EN' name='lc'>
<input type='submit' value='Proceed to Payment' name='B1'>
</form>
</div><!--redirect-->
<script>document.getElementById('form').submit();</script>";
我不知道为什么插入功能会发生两次。我在INSERT函数之前回复了一个警告,它只在页面加载时发送一个警报,所以好像它只在代码中运行一次。我删除了表单代码,认为可能是Javascript自动重定向可能导致代码循环,但我得到了相同的结果。我还删除了INSERT查询之后的SELECT查询,认为它可能导致重复,但也没有做到这一点。
我正在使用SELECT查询,以便在成功结束时连接GET变量并取消PayPal表单的URL。
我不知道为什么它会循环两次。有什么想法吗?谢谢你的帮助!