2015-11-07 79 views
0

首先,orderdetail.php是POST數據從order.php和orderdetail是鏈接到貝寶頁面給付款。點擊「PAY」按鈕後,它會將用戶導向PayPal頁面,購物車表中的數據將被刪除並插入到MYSQL的訂購表中。爲什麼我的編碼無法插入訂購表並鏈接到PayPal?

這裏是orderdetail.php:

<div class="shopmain shopbox" style="margin-bottom:10px;"> 
<?php  

$result=mysql_query("select * from cart where username='$user'"); 
$rownum=mysql_num_rows($result); 

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

?> 

<ul> 
     <li class="boxa"> <img src="<?php echo $row['pass_url']?>" width="130" height="98"> </li> 
     <li class="boxb"> 
     <h3>Food name</h3> 
     <h4><?php echo $row['pass_name']?></h4> 
     </li> 

     <li class="boxc"> 
     <h3>Restaurant</h3> 
     <h4><?php echo $row['pass_restaurant']?></h4> 
     </li> 

     <li class="boxc"> 
     <h3>Food Price</h3> 
     <h4>RM <?php echo $row['pass_price']?> </h4> 
     </li> 

     <li class="boxc"> 
     <h3>Order num</h3> 
     <h4> <?php echo $row['pass_num']?> </h4> 
     </li> 

     <li class="boxc"> 
     <h3>Total</h3> 
     <h4>RM <i><?php echo $row['pass_total']?></i></h4> 
     </li> 
</ul> 
    <?php } ?> 
    <form action="paydetail.php?pass_total=<?php echo $row2['SUM(pass_total)'];?>" method="get" id="pay"> 
    <?php  

$result2=mysql_query("select SUM(pass_total) from cart where username='$user'"); 
while($row2=mysql_fetch_array($result2)){ 
    ?> 

<div class="total" style="font-size:32px;"> Total : <strong></strong>RM <i><?php echo $row2['SUM(pass_total)'];?></i></div> 
</div> 
<?php }?> 
<div class="detaltop"> 
     <h3>Orderer information </h3> 
</div> 

<div class="pay"> 

    <ul> 
<?php 

$arr = mysql_query("select * from customer where username='$user'"); 
$result = mysql_fetch_array($arr) 
?> 
    <li><span>Orderer's name &nbsp;&nbsp; </span><?php echo $result["fullname"]; ?></li> 
    <li><span>Contact number &nbsp;&nbsp; </span><?php echo $result["hpno"]; ?> </li> 
    <li><span>Email &nbsp;&nbsp; </span><?php echo $result["email"]; ?> </li> 



    <input name="submit" type="submit" value="PAY" class="buttoncss"> 
    </ul> 
</form> 
</div>   
</div> 

後的 「支付」 按鈕的用戶點擊,直接到paydetail.php:

<?php 
session_start(); 
ini_set('error_reporting', 'E_ALL^E_NOTICE'); 
header("Content-type: text/html; charset=utf-8"); 
include("conn.php"); 

$user = $_SESSION['username']; 

$result1=mysql_query("select * from cart where username='$user'"); 

$row=mysql_fetch_array($result1); 

$result2=mysql_query("select * from customer where username='$user'"); 

$row1=mysql_fetch_array($result2); 

$result=mysql_query("INSERT INTO `ordering` (`orderID` ,`order_no` ,`order_user` ,`order_foods_id`,`order_num` ,`order_name`,`order_phone`,`order_email`,`order_time` ,`order_pay`) VALUES('','$booknum','$user','$row[pass_id]','$row[pass_num]','$row1[fullname]','$row1[hpno],'$row1[email]',now(),'$row[pass_total]')"); 

mysql_query("delete from cart where username='$user'"); 


?> 

<!DOCTYPE > 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Tumy</title> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<link href="css/style.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="scripts/jquery.min.js"></script> 
</head> 
<body> 
<div style="display:none"> 
<form action="https://www.paypal.com/cgi-bin/webcsr" method="post" id="pay"> 
    <input name="cmd" type="hidden" value="_xclick" /> 
    <input name="seat" type="hidden" value="" /> 
    <input name="business" type="text" class="paybox" value="[email protected]" /> 
    <input name="item_name" type="text" class="paybox" value="<?php echo "goods"; ?>" /> 
    <input name="amount" type="text" class="paybox" value="<?php echo $total; ?>" /> 
    <input name="currency_code" type="hidden" value="MYR" /> 
</form> 
</div> 
<script> 

$(document).ready(function() { 

$("#pay").submit(); 


}); 
</script> 
</body> 
</html> 

所以我要問,爲什麼從購物車中的數據無法插入訂購表中?但是點擊「PAY」按鈕後,它可以從購物車刪除數據。

+0

您的標題問題和最後一段是不同的。你的問題是什麼? – user1122069

+0

你可以看到這個Paypal的教程https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/formbasics/ –

回答

0

我只會回答你們其中一個問題。他們不相關。修復它時,編輯標題並創建一個新帖子。你的mysql語法有錯誤。寫下面的代碼

if (!$result) { echo 'Mysql Error'; exit();} 

然後你需要找出那個錯誤是什麼。這可能是很多事情,但首先用PHPMyadmin測試查詢並刪除「$ booknum」周圍的單引號並寫入「。$ booknum」。

然後研究如何逃避字符串的安全性。 mysql_real_escape($ booknum)或類似的東西。

"INSERT INTO `ordering` (`orderID` ,`order_no` ,`order_user` ,`order_foods_id`,`order_num` ,`order_name`,`order_phone`,`order_email`,`order_time` ,`order_pay`) VALUES('',".$booknum.",'$user','$row[pass_id]','$row[pass_num]','$row1[fullname]','$row1[hpno],'$row1[email]',now(),'$row[pass_total]')"