佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 2061|回复: 8

php insert into select的问题

[复制链接]
发表于 13-9-2012 10:17 PM | 显示全部楼层 |阅读模式
我想要把部分records从一个table insert去另一个,不过我的orderID,Address,town,state,total,postcode是一样的。
  1. <?php
  2. session_start();
  3. include ("connect.php");

  4. $OrderID=$_POST['OrderID'];
  5. $Total=$_POST['Total'];
  6. $Address=$_POST['address'];
  7. $Town=$_POST['town'];
  8. $State=$_POST['state'];
  9. $Postcode=$_POST['postcode'];


  10. $sql="INSERT INTO orderrecord(OrderID, ProductID,ProductName,UnitPrice,Quantity,TotalPrice,Total,Address,Town,State,Postalcode) Values ('$OrderID',(SELECT cart.ProductID,cart.ProductName,cart.UnitPrice,cart.Quantity,cart.TotalPrice from cart),'$Total','$Address','$Town','$State','$Postcode')";
  11. $result = $db->query($sql);




  12. if(! $result )
  13. {
  14. die('<script type="text/javascript">alert("Unsuccessful payment")</script>');
  15. echo mysql_error();   

  16.   
  17. }
  18. else{
  19. echo '<script type="text/javascript">alert("Payment Successfully")</script>';
  20.   echo "<script language='javascript'>window.location='login.php'</script>";
  21. }

  22. ?>
复制代码
一直不能成功,是哪里出了问题吗?
回复

使用道具 举报


ADVERTISEMENT

发表于 14-9-2012 01:24 AM | 显示全部楼层
Can try the following:

$sql="INSERT INTO orderrecord(OrderID, ProductID,ProductName,UnitPrice,Quantity,TotalPrice,Total,Address,Town,State,Postalcode)
(SELECT '$OrderID', cart.ProductID,cart.ProductName,cart.UnitPrice,cart.Quantity,cart.TotalPrice,
'$Total','$Address','$Town','$State','$Postcode' from cart)";
回复

使用道具 举报

发表于 14-9-2012 03:33 AM | 显示全部楼层
用一些工具.. 做 query testing..
如 SQLyog..
回复

使用道具 举报

 楼主| 发表于 14-9-2012 07:48 AM | 显示全部楼层
php+.net 发表于 14-9-2012 01:24 AM
Can try the following:

$sql="INSERT INTO orderrecord(OrderID, ProductID,ProductName,UnitPrice,Qua ...

还是不可以啊。。。我的cart table里有很多records,不只一个。是不是要用loop?
回复

使用道具 举报

发表于 14-9-2012 12:25 PM | 显示全部楼层
h@@ 发表于 14-9-2012 07:48 AM
还是不可以啊。。。我的cart table里有很多records,不只一个。是不是要用loop?

No need to use loop.
Any error message?

Try to display/show the exact value of $sql and then run it in your phpMyAdmin or any other database tool and see what is the error.

回复

使用道具 举报

 楼主| 发表于 14-9-2012 12:42 PM | 显示全部楼层
jasonmun 发表于 14-9-2012 03:33 AM
用一些工具.. 做 query testing..
如 SQLyog..

我的sql应该对了。。只是不懂为什么在php insert 不了
回复

使用道具 举报

Follow Us
 楼主| 发表于 14-9-2012 12:46 PM | 显示全部楼层
php+.net 发表于 14-9-2012 12:25 PM
No need to use loop.
Any error message?

1.png 2.png
没有error message。submit了就只有unsuccessful payment罢了

回复

使用道具 举报

 楼主| 发表于 14-9-2012 12:50 PM | 显示全部楼层
php+.net 发表于 14-9-2012 12:25 PM
No need to use loop.
Any error message?

现在可以了。。在cart table还有一个column我忘了写。。谢谢啊
回复

使用道具 举报


ADVERTISEMENT

发表于 22-10-2012 11:24 PM | 显示全部楼层
h@@ 发表于 14-9-2012 12:46 PM
没有error message。submit了就只有unsuccessful payment罢了

请问你的unit price是从database抓是吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 6-10-2025 08:39 AM , Processed in 0.146025 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表