我有一个表单,通过该表单处理购物车数据,并使用paypal处理它的onclick按钮。我已经制作了一个success.php
页面,当交易完成时它将自动返回。所有字段都成功保存在数据库中,但我坚持用户将上传的文件。我的问题是,当paypal checkout成功返回到success.php
页面时,有没有办法将上传的文件名保存在数据库中?如果是,那么如何在paypal按钮内传递变量?我已经对此进行了很多搜索。但没有人帮我解决问题。任何建议或指南将不胜感激。
的 form.php的
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" enctype="multipart/form-data">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="sriniv_1293527277_biz@inbox.com">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="file" name="custom" >
<Label> Select shipment interval (optional):
<select id="shipment_option" name="shipment">
<option selected="selected" value="7" id="7">7</option>
<option value="6" id="6"> 6 </option>
<option value="5" id="5">5 </option>
</select></Label>
<input type="hidden" name="return" value="success.php">
<input type="hidden" name="cancel_return" value="paypal_cancel.php">
<input type="image" name="submit" border="0" src="LG.gif">
</form>
success.php
<?php
session_start();
include("db/db.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
<html>
<title>Success</title>
<body>
<?php
if(isset($_SESSION['cart']) && isset ($_SESSION['login_email'])){
$total=0;
$email=$_SESSION['login_email'];
$ships=$_POST['shipment'];
$file=$_FILES['file']['custom'];//this is how i am trying to get the file name. But it doesnot work
//customer information
$query1=mysqli_query($con,"select * from customers where email='$email'");
while($rows=mysqli_fetch_array($query1,MYSQLI_ASSOC))
{
$user=$rows['name'];
$user_id=$rows['serial'];
}
//orders and order details.
$que=mysqli_query($con,"insert into orders(custom_file,date,customerid,status,ship_days) values('$file',CURRENT_TIMESTAMP(),'$user_id','confirmed','$ships')");
if($que)
{
$m=move_uploaded_file($_FILES['file']['name'],'./ServerUploadedFiles/'.$user.$file);
$q=mysqli_query($con,"select serial from orders where customerid='$user_id' and date=CURRENT_TIMESTAMP()");
while($row1=mysqli_fetch_array($q,MYSQLI_ASSOC))
{
$order_id=$row1['serial'];
}
foreach($_SESSION['cart'] as $id => $value){
$subtotal=$value['price']*$value['quantity'];
$pid=$value['id'];
$quantity=$value['quantity'];
$color=$value['color'];
$size=$value['size'];
$total+= $subtotal;
$query= mysqli_query($con, "INSERT INTO order_detail(orderid,productid,quantity,price,color,size) VALUES ($order_id, $pid, $quantity, $subtotal, '$color', '$size')");
}
}
//payment details for paypal
$amount=$_GET['amt'];
$currency=$_GET['cc'];
$trx_id=$_GET['tx'];
$insert_payments= mysqli_query($con,"insert into payments(amount,cust_id,order_id,trx_id,currency) values('$amount','$user_id','$order_id','$trx_id','$currency')");
if($amount==$total)
{
unset($_SESSION['cart']);
echo "<h2>Hello". $user."You have successfully done purchasing process.Please <a href='profile.php'>Go to your account</a>!</h2>";
}
else
{
echo "<h2>Hello". $user."Your payment was not successful.Please <a href='profile.php'>Go to your account</a>!</h2>";
}
}
?>
</body>
</html>